954,593 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Asp.net Sql Query

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")
m_saahil
Newbie Poster
1 post since Sep 2007
Reputation Points: 10
Solved Threads: 0
 

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()
hollystyles
Veteran Poster
1,182 posts since Feb 2005
Reputation Points: 262
Solved Threads: 68
 

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.

adamm84
Newbie Poster
5 posts since Sep 2007
Reputation Points: 10
Solved Threads: 1
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You