Hi,
I am new to VB.Net and I am trying to create a program that inserts data into a SQL table. Below you will find my code that gives me the following error: Connection Property has not been initialized
I cannot see (from inexperience) where I am having the issue.
Many thanks!!!
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.BillTableAdapter.Fill(Me.SenTestDataSet.Bill)
Dim cmd As SqlClient.SqlCommand = New SqlClient.SqlCommand
Dim Conn = New SqlClient.SqlConnection
Conn.ConnectionString = "Data Source=[ServerName]; Initial Catalog=SenTest; password=""[Password]""; persist security info =True; user id=sa; workstation ID=Man1; Packet Size =4096"
Dim InsertQuery As String
daBill.SelectCommand = cmdSelectBill
daBill.UpdateCommand = cmdUpdateBill
daBill.InsertCommand = cmdInsertBill
daBill.DeleteCommand = cmdDeleteBill
daBill.SelectCommand.CommandText = "Select * from Bill"
daBill.SelectCommand.Connection = Conn
daBill.InsertCommand.CommandText = "Insert Into Bill(BillNumber, Description) Values (@BillNumber, @Description)"
daBill.InsertCommand.Connection = Conn
cmd.Parameters.Add("@BillNumber", SqlDbType.Char, 10, "@BillNumber")
cmd.Parameters.Item("@BillNumber").Value = TextBox1.Text
cmd.Parameters.Add("@Description", SqlDbType.Char, 1000, "@Description")
cmd.Parameters.Item("@Description").Value = TextBox2.Text
Conn.open()
cmd.Connection = Conn
InsertQuery = cmd.ExecuteNonQuery
Conn.Close()
End Sub