Hi all
I need urgent help to complete my project
I am unable to update my sql database.I have to update the database using textbox value as primary key and the other tools are textbox,dropdownlist and calender which i have used
I am doin project on ASP.NET using vb.net so plzz give me the coding in vb.net

the code i have written is as shown below
please help me out soon

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
myConnection = New SqlConnection("server =sqlserver.htsdomain.net;uid=sa;pwd=;database=CentralHTS")
        'myConnection.Open()
        'myCommand = New SqlCommand(UPDATE task  SET Numbercardused=@TextBox1.text,Numberfreetv=@Dropdownlist1,Datefrom,Dateto  where (PhoneNumber=@TextBox1.Text))
        'Response.Write("Record Updated")

You need to put strings in double quotes. The sql string argument to the SqlCommand constructor needs to be quoted. myCommand = New SqlCommand("UPDATE task SET ... don't put @ in front of the webserver control instances (you are confusing them with TSQL parameters)

myCommand = New SqlCommand("UPDATE task  SET Numbercardused=" & TextBox1.text & " ...

The dropDownList you need to use the Selectedvalue property

... Numberfreetv=" & Dropdownlist1.SelectedValue & " ...

You need to execute the command now it's built:

myCommand.ExecuteNonQuery()

putting sql inline like that is extremely dangerous and not safe at all, i would suggest moving your sql to stored procedures, or at least parameterizing your query, you should also do some back end data verification, e.g. check for nulls, emptry strings, etc.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.