string oConnStr = "data source=localhost;initial catalog=Northwind;integrated security=SSPI;persist security info=False;packet size=4096"; // Make connection to VFP database SqlConnection oConn = new SqlConnection(); oConn.ConnectionString = oConnStr; oConn.Open(); // Create a Command object with select statement string strSelect = "SELECT FirstName,LastName,Title FROM EMPLOYEES"; SqlCommand oSelectCommand = new SqlCommand(strSelect, oConn); string strInsert = "[NewInsertCommand]"; SqlCommand oInsertCommand = new SqlCommand(strInsert, oConn); oInsertCommand.CommandType = System.Data.CommandType.StoredProcedure; 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 SqlDataAdapter da = new SqlDataAdapter(); da.SelectCommand = oSelectCommand; da.InsertCommand = oInsertCommand; // Create a DataSet DataSet ds = new DataSet(); // Fill the DataSet with table information da.Fill(ds, "Employees"); DataRow dr = 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();>Cathi,
>>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
>>
>>>>Dim strInsert As [String] = "[NewInsertCommand]" >>Dim oInsertCommand As New SqlCommand(strInsert, oConn) >>oInsertCommand.CommandType = System.Data.CommandType.StoredProcedure >>>>
>>>>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 >>>>>>>>>>>>