Dim sqlsyntax As String
Dim result As String
sqlsyntax = "INSERT INTO tblOfficeEquipmentProfile(OE_ID, OE_Category,OE_SubCategory, OE_Name, OE_User, OE_Brand, OE_Model, OE_Specs, OE_SerialNo, OE_PropertyNo, OE_Static_IP, OE_Vendor, OE_PurchaseDate, OE_WarrantyInclusiveYear, OE_WarrantyStatus, OE_Status, OE_Dept_Code,OE_Location_Code,OE_Remarks)" _
& "VALUES(@OE_ID,@OE_Category,@OE_SubCategory,@OE_Name,@OE_User,@OE_Brand,@OE_Model,@OE_Specs,@OE_SerialNo,@OE_PropertyNo,@OE_Static_IP,@OE_Vendor,@OE_PurchaseDate,@OE_WarrantyInclusiveYear,@OE_WarrantyStatus,@OE_Status,@OE_Dept_Code,@OE_Location_Code,@OE_Remarks)"
Dim adapter As SqlDataAdapter
adapter.InsertCommand = New SqlCommand(sqlsyntax, sqlconn)
adapter.InsertCommand.Parameters.Add("@OE_ID", SqlDbType.VarChar)
adapter.InsertCommand.Parameters.Add("@OE_Category", SqlDbType.Char)
adapter.InsertCommand.Parameters.Add("@OE_SubCategory", SqlDbType.Char)
adapter.InsertCommand.Parameters.Add("@OE_Name", SqlDbType.VarChar)
adapter.InsertCommand.Parameters.Add("@OE_User", SqlDbType.VarChar)
adapter.InsertCommand.Parameters.Add("@OE_Brand", SqlDbType.VarChar)
adapter.InsertCommand.Parameters.Add("@OE_Model", SqlDbType.VarChar)
adapter.InsertCommand.Parameters.Add("@OE_Specs", SqlDbType.VarChar)
adapter.InsertCommand.Parameters.Add("@OE_SerialNo", SqlDbType.VarChar)
adapter.InsertCommand.Parameters.Add("@OE_PropertyNo", SqlDbType.VarChar)
adapter.InsertCommand.Parameters.Add("@OE_Static_IP", SqlDbType.VarChar)
adapter.InsertCommand.Parameters.Add("@OE_Vendor", SqlDbType.VarChar)
adapter.InsertCommand.Parameters.Add("@OE_PurchaseDate", SqlDbType.SmallDateTime)
adapter.InsertCommand.Parameters.Add("@OE_WarrantyInclusiveYear", SqlDbType.Int)
adapter.InsertCommand.Parameters.Add("@OE_WarrantyStatus", SqlDbType.Char)
adapter.InsertCommand.Parameters.Add("@OE_Status", SqlDbType.VarChar)
adapter.InsertCommand.Parameters.Add("@OE_Dept_Code", SqlDbType.Char)
adapter.InsertCommand.Parameters.Add("@OE_Location_Code", SqlDbType.Char)
adapter.InsertCommand.Parameters.Add("@OE_Remarks", SqlDbType.VarChar)
For i As Integer = 0 To DataGrid1.VisibleRowCount - 1
'adapter.InsertCommand.Parameters(0).Value = Convert.ToInt32(txtEmpID.Text.Trim)
adapter.InsertCommand.Parameters(0).Value = DataGrid1(i, 0).GetType
adapter.InsertCommand.Parameters(1).Value = DataGrid1(i, 1).GetType
adapter.InsertCommand.Parameters(2).Value = DataGrid1(i, 2).GetType
adapter.InsertCommand.Parameters(3).Value = DataGrid1(i, 3).GetType
adapter.InsertCommand.Parameters(4).Value = DataGrid1(i, 4).GetType
adapter.InsertCommand.Parameters(5).Value = DataGrid1(i, 5).GetType
adapter.InsertCommand.Parameters(6).Value = DataGrid1(i, 6).GetType
adapter.InsertCommand.Parameters(7).Value = DataGrid1(i, 7).GetType
adapter.InsertCommand.Parameters(8).Value = DataGrid1(i, 8).GetType
adapter.InsertCommand.Parameters(9).Value = DataGrid1(i, 9).GetType
adapter.InsertCommand.Parameters(10).Value = DataGrid1(i, 10).GetType
adapter.InsertCommand.Parameters(11).Value = DataGrid1(i, 11).GetType
adapter.InsertCommand.Parameters(12).Value = DataGrid1(i, 12).GetType
adapter.InsertCommand.Parameters(13).Value = DataGrid1(i, 13).GetType
adapter.InsertCommand.Parameters(14).Value = DataGrid1(i, 14).GetType
adapter.InsertCommand.Parameters(15).Value = DataGrid1(i, 15).GetType
adapter.InsertCommand.Parameters(16).Value = DataGrid1(i, 16).GetType
adapter.InsertCommand.Parameters(17).Value = DataGrid1(i, 17).GetType
adapter.InsertCommand.Parameters(18).Value = DataGrid1(i, 18).GetType
result = adapter.InsertCommand.ExecuteNonQuery()
MsgBox("success fully added")
adapter.InsertCommand.Parameters.Clear()
Next
先生,我将代码修改为以下 sql 数据,
但在这里返回错误
---->adapter.InsertCommand = New SqlCommand(sqlsyntax, sqlconn)
错误:EOEHR.exe 中出现“System.NullReferenceException”类型的未处理异常
附加信息:对象引用未设置为对象的实例。