Torna al Thread

' Declare local variables and objects... Dim intPosition As Integer Dim objCommand As OleDbCommand = New OleDbCommand() ' Save the current record position... intPosition = objCurrencyManager.Position ' We must open the connection to the Microsoft Access database objConnection.Open() ' Set the SqlCommand object properties... objCommand.Connection = objConnection ' We set using standard SQL statement for inserting ' data in the database objCommand.CommandText = "INSERT INTO Customers " & _ "(id,FirstName, LastName,Address) " & _ "VALUES(@id,@firstname,@lastname,@address);" Dim KIAVE As String = Format(DateTime.Parse(Now), "dd/MM/yyyy") + Format(DateTime.Parse(Now), "hh:mm:ss") ' We must to add parameters to the oledbCommand object ' Parameter for the FirstName column objCommand.Parameters.AddWithValue("@id", KIAVE) objCommand.Parameters.AddWithValue("@firstname", txtFirstName.Text) ' Parameter for the LastName column objCommand.Parameters.AddWithValue("@lastname", txtLastName.Text) ' Parameter for the Address column... objCommand.Parameters.AddWithValue("@address", txtAddress.Text) ' Execute the OleDBCommand object to insert the new data Try objCommand.ExecuteNonQuery() Catch OleDbExceptionErr As OleDbException MessageBox.Show(OleDbExceptionErr.Message) End Try ' Close the connection... objConnection.Close() ' Fill the dataset and bind the fields... FillDataSetAndView() BindFields()
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5