michelleHEC
Programmer
i have a form that has textbox's built based on how many members are in a particular group. i use arrays to build them and i have no trouble inserting into the database from the textbox's but i cannot figure out how to update. Should i use a command or a data adapter? i havent had success using either. here is my latest try;
Dim cnUpdate As New SqlClient.SqlConnection()
cnUpdate.ConnectionString = "data source=LocalHost;" & _
"initial catalog=EMPLOYEE;persist security info=False;user id=sa"
cnUpdate.Open()
Dim sqlchk As String = "Update tmpDailyCrewTest set Name = @Name, TruckNoRg = @TruckNoRg Where Foreman = @Foreman order by name"
Dim daUpdate As New SqlClient.SqlDataAdapter(sqlchk, cnUpdate)
Dim prmForeman As SqlClient.SqlParameter = daUpdate.UpdateCommand.Parameters.Add(New SqlClient.SqlParameter("@Foreman", SqlDbType.VarChar, 20))
Dim prmName As SqlClient.SqlParameter = daUpdate.UpdateCommand.Parameters.Add(New SqlClient.SqlParameter("@Name", SqlDbType.VarChar, 25))
Dim prmTruckNoRg As SqlClient.SqlParameter = daUpdate.UpdateCommand.Parameters.Add(New SqlClient.SqlParameter("@TruckNoRg", SqlDbType.Decimal, 9))
For intC = 0 To intCrews
For intN = 0 To intCrewCount
daUpdate.UpdateCommand.Parameters("@Name"
.Value = lblName(intC).Text
daUpdate.UpdateCommand.Parameters("@TruckNoRg"
.Value = txtTruckRg(intC, intN).Text
daUpdate.UpdateCommand.Parameters("@Foreman"
.Value = lblForeman.Text
daUpdate.UpdateCommand.ExecuteNonQuery()
Next
Next
my error is "object reference not set as instance of an object on the line where i am setting the parameter for the foreman.???
any help would be appreciated, i am knocking my head against the wall about now!
michelle
Dim cnUpdate As New SqlClient.SqlConnection()
cnUpdate.ConnectionString = "data source=LocalHost;" & _
"initial catalog=EMPLOYEE;persist security info=False;user id=sa"
cnUpdate.Open()
Dim sqlchk As String = "Update tmpDailyCrewTest set Name = @Name, TruckNoRg = @TruckNoRg Where Foreman = @Foreman order by name"
Dim daUpdate As New SqlClient.SqlDataAdapter(sqlchk, cnUpdate)
Dim prmForeman As SqlClient.SqlParameter = daUpdate.UpdateCommand.Parameters.Add(New SqlClient.SqlParameter("@Foreman", SqlDbType.VarChar, 20))
Dim prmName As SqlClient.SqlParameter = daUpdate.UpdateCommand.Parameters.Add(New SqlClient.SqlParameter("@Name", SqlDbType.VarChar, 25))
Dim prmTruckNoRg As SqlClient.SqlParameter = daUpdate.UpdateCommand.Parameters.Add(New SqlClient.SqlParameter("@TruckNoRg", SqlDbType.Decimal, 9))
For intC = 0 To intCrews
For intN = 0 To intCrewCount
daUpdate.UpdateCommand.Parameters("@Name"
daUpdate.UpdateCommand.Parameters("@TruckNoRg"
daUpdate.UpdateCommand.Parameters("@Foreman"
daUpdate.UpdateCommand.ExecuteNonQuery()
Next
Next
my error is "object reference not set as instance of an object on the line where i am setting the parameter for the foreman.???
any help would be appreciated, i am knocking my head against the wall about now!
michelle