这是我的vb代码,用于在表中插入新记录,但我得到的Object引用未设置为对象错误的实例。
Protected Sub Submit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Submit.Click
Dim datasource As New SqlDataSource()
datasource.ConnectionString = ConfigurationManager.ConnectionStrings("SqlDataSource1").ToString()
datasource.InsertCommandType = SqlDataSourceCommandType.Text
datasource.InsertCommand = "INSERT INTO InstallerCalls ([Date], [Associate], [StoreNum], [TMName], [NewStoreNum], [ShopName], [ContactName], [ContactTitle], [City], [State], [Comments]) VALUES (@Date, @Associate, @StoreNum, @TMName, @NewStoreNum, @ShopName, @ContactName, @ContactTitle, @City, @State, @Comments)"
datasource.InsertParameters.Add("@Date", txtDate.Text)
datasource.InsertParameters.Add("@Associate", txtAssociate.Text)
datasource.InsertParameters.Add("@StoreNum", txtStoreNum.Text)
datasource.InsertParameters.Add("@TMName", txtTMName.Text)
datasource.InsertParameters.Add("@NewStoreNum", txtNewStoreNum.Text)
datasource.InsertParameters.Add("@ShopName", txtShopName.Text)
datasource.InsertParameters.Add("@ContactName", txtContactName.Text)
datasource.InsertParameters.Add("@ContactTitle", txtContactTitle.Text)
datasource.InsertParameters.Add("@City", txtCity.Text)
datasource.InsertParameters.Add("@State", txtState.Text)
datasource.InsertParameters.Add("@Comments", txtComments.Text)
datasource.Insert()
End Sub
答案 0 :(得分:0)
当您收到包含此消息的错误消息时,表示您尝试访问未定义的property
内容(method
或object
),即{{{ 1}}。在这种情况下,您需要调试代码并找到哪个对象为null以及您得到错误的行。