Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

updating dynamicly built textbox's

Status
Not open for further replies.

michelleHEC

Programmer
Oct 20, 2003
95
0
0
US
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
 
Does it work if you include the New keyword? ie.

Code:
Dim prmForeman As New SqlClient.SqlParameter = daUpdate.UpdateCommand.Parameters.Add(New SqlClient.SqlParameter("@Foreman", SqlDbType.VarChar, 20))

T0AD

There's a thin line between genius, and insanity!
 
i tried that but i got the dreaded blue line under the rest of the statement.
thanks for your support, any other ideas?
 
Michelle try this code,(Example:Dataset = "DSCUSTOMER1",tablename="CUSTOMER")

Try
Me.BindingContext(Dscustomer1.CUSTOMER).EndCurrentEdit()
DACUSTOMER.Update(Dscustomer1)
Catch x As Exception
'Add error Message
End Try

Handoko
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top