为什么数据不会插入到mysql数据库中

时间:2014-05-15 20:06:05

标签: mysql asp.net vb.net insert

这是我的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

1 个答案:

答案 0 :(得分:0)

当您收到包含此消息的错误消息时,表示您尝试访问未定义的property内容(methodobject),即{{{ 1}}。在这种情况下,您需要调试代码并找到哪个对象为null以及您得到错误的行。