CREATE PROCEDURE dbo.NewInsertCommand
(
@LastName nvarchar(20),
@FirstName nvarchar(10),
@Title nvarchar(30)
)
AS
INSERT INTO Employees(LastName, FirstName, Title) VALUES (@LastName, @FirstName, @Title);
GO
The only change I made to my .NET code was change the CommandText and set the CommandType to the following:Dim strInsert As [String] = "[NewInsertCommand]" Dim oInsertCommand As New SqlCommand(strInsert, oConn) oInsertCommand.CommandType = System.Data.CommandType.StoredProcedureThe Title field is null in the Employees table in SQL Server.
>>Dim oConnStr As String = "data source=localhost;initial catalog=Northwind;integrated security=SSPI;persist security info=False;packet size=4096" >> >>' Make connection to database >>Dim oConn As New SqlConnection() >>oConn.ConnectionString = oConnStr >>oConn.Open() >> >>' Create a Command object with select statement >>Dim strSelect As [String] = "SELECT FirstName,LastName,Title FROM EMPLOYEES" >>Dim oSelectCommand As New SqlCommand(strSelect, oConn) >> >>' Create a Command object with insert statement >>Dim strInsert As [String] = "INSERT INTO EMPLOYEES(FirstName,LastName,Title) values (@FirstName,@LastName,@Title)" >> >>Dim oInsertCommand As New SqlCommand(strInsert, oConn) >>oInsertCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@FirstName", System.Data.SqlDbType.NVarChar, 10, "FirstName")) >>oInsertCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@LastName", System.Data.SqlDbType.NVarChar, 20, "LastName")) >>oInsertCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@Title", System.Data.SqlDbType.NVarChar, 30, "Title")) >> >>' Create a DataAdapter >>Dim da As New SqlDataAdapter() >>da.SelectCommand = oSelectCommand >>da.InsertCommand = oInsertCommand >> >>' Create a DataSet >>Dim ds As New DataSet() >> >>' Fill the DataSet with table information >>da.Fill(ds, "Employees") >> >>Dim dr As DataRow = ds.Tables(0).NewRow() >>dr("FirstName") = "NetFN" >>dr("LastName") = "NetLN" >>dr("Title") = Convert.DBNull >>ds.Tables(0).Rows.Add(dr) >> >>da.Update(ds.Tables(0)) >> >>oConn.Close() >>>>
>>>>insert into TABLENAME (FIELD1, FIELD2) values ('TEXT', NULL)
>>>>
>>>>>>>>rowCustomer("ContactName") = Convert.DBNull >>>>>>>>