Inserting values into the database using a asp.net button click

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Dec 2008
Posts: 37
Reputation: kodingkarthik is an unknown quantity at this point 
Solved Threads: 0
kodingkarthik kodingkarthik is offline Offline
Light Poster

Inserting values into the database using a asp.net button click

 
0
  #1
Dec 15th, 2008
Hi all,


I am new to asp.net programming and i have to design a website which should accept values from the user and store it in the databse on a button click event.

I am not able to do it In fact i have written a code for button click the code is as follows:

  1. Dim conn As New SqlConnection
  2. conn.ConnectionString = "data source=.\\SQLEXPRESS;initial catalog=HRDATA;integrated security=true"
  3. Dim cmd As New SqlCommand
  4. cmd.CommandText = "INSERT INTO Employee Data values ('" & txt_name.Text & "')"
  5. cmd.Connection = conn
  6. conn.Open()
  7. cmd.ExecuteNonQuery()
  8. conn.Close()

the problem that i am facing is at
cmd.ExecuteNonQuery()
the error message i am getting is tht the ExecuteNonQuery is not initialized..


Thanks in advance ...
Karthik.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 63
Reputation: 4advanced is an unknown quantity at this point 
Solved Threads: 10
4advanced 4advanced is offline Offline
Junior Poster in Training

Re: Inserting values into the database using a asp.net button click

 
0
  #2
Dec 15th, 2008
Maybe cmd.CommandType needs to be stated as text.
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 645
Reputation: binoj_daniel is an unknown quantity at this point 
Solved Threads: 17
binoj_daniel's Avatar
binoj_daniel binoj_daniel is offline Offline
DaniWeb Expert

Re: Inserting values into the database using a asp.net button click

 
0
  #3
Dec 16th, 2008
try cmd.CommandType = CommandType.Text before

cmd.CommandText = "INSERT ...
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 37
Reputation: kodingkarthik is an unknown quantity at this point 
Solved Threads: 0
kodingkarthik kodingkarthik is offline Offline
Light Poster

Re: Inserting values into the database using a asp.net button click

 
0
  #4
Dec 18th, 2008
Hi Dani,

Thanks for your reply and i have a new problem with the insert command that iam using please help me out

  1. myCommand = New SqlCommand("Insert into Employee Data values(ddlid.selectedItem,'" & txtname.Text & "',ddldesig.selectedItem,'" & txtcontno & "')", "myConnection")

Whats wrong with my insert command that i am using in my code...


Thanks in advance
Karthik.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 104
Reputation: Aneesh_Argent is an unknown quantity at this point 
Solved Threads: 18
Aneesh_Argent Aneesh_Argent is offline Offline
Junior Poster

Re: Inserting values into the database using a asp.net button click

 
0
  #5
Dec 18th, 2008
Try this :
DdlId.SelectedItem.Text;
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 173
Reputation: Kusno is an unknown quantity at this point 
Solved Threads: 13
Kusno's Avatar
Kusno Kusno is offline Offline
Junior Poster

Re: Inserting values into the database using a asp.net button click

 
0
  #6
Dec 19th, 2008
Hi, you still forgot for DropDownList

  1. myCommand = New SqlCommand("Insert into Employee Data values('" & ddlid.selectedItem & "','" & txtname.Text & "','" & ddldesig.selectedItem & "','" & txtcontno.Text & "')", "myConnection")
Last edited by peter_budo; Dec 21st, 2008 at 4:55 am. Reason: Please, either use [code] or [code=asp.net] (or other langiage as necessary). DO NOT USE [QUOTE]
NEVER NEVER NEVER GIVE UP
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the ASP.NET Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC