User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP.NET section within the Web Development category of DaniWeb, a massive community of 456,510 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,681 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting
Views: 2319 | Replies: 2
Reply
Join Date: Sep 2007
Posts: 1
Reputation: m_saahil is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
m_saahil m_saahil is offline Offline
Newbie Poster

Asp.net Sql Query

  #1  
Sep 25th, 2007
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")
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Feb 2005
Location: Braintree, UK
Posts: 1,166
Reputation: hollystyles will become famous soon enough hollystyles will become famous soon enough 
Rep Power: 7
Solved Threads: 59
hollystyles's Avatar
hollystyles hollystyles is offline Offline
Veteran Poster

Re: Asp.net Sql Query

  #2  
Sep 25th, 2007
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()
Last edited by hollystyles : Sep 25th, 2007 at 9:12 am.
==========================================
Yadda yadda yadda...
Web junky, fevered monkey
Reply With Quote  
Join Date: Sep 2007
Posts: 5
Reputation: adamm84 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
adamm84 adamm84 is offline Offline
Newbie Poster

Re: Asp.net Sql Query

  #3  
Sep 25th, 2007
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.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb ASP.NET Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the ASP.NET Forum

All times are GMT -4. The time now is 3:49 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC