DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   ASP.NET (http://www.daniweb.com/forums/forum18.html)
-   -   Inserting values into the database using a asp.net button click (http://www.daniweb.com/forums/thread162338.html)

kodingkarthik Dec 15th, 2008 6:52 am
Inserting values into the database using a asp.net button click
 
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:

Dim conn As New SqlConnection
        conn.ConnectionString = "data source=.\\SQLEXPRESS;initial catalog=HRDATA;integrated security=true"
        Dim cmd As New SqlCommand
        cmd.CommandText = "INSERT INTO Employee Data values ('" & txt_name.Text & "')"
        cmd.Connection = conn
        conn.Open()
        cmd.ExecuteNonQuery()
        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.

4advanced Dec 15th, 2008 7:00 am
Re: Inserting values into the database using a asp.net button click
 
Maybe cmd.CommandType needs to be stated as text.

binoj_daniel Dec 16th, 2008 4:59 pm
Re: Inserting values into the database using a asp.net button click
 
try cmd.CommandType = CommandType.Text before

cmd.CommandText = "INSERT ...

kodingkarthik Dec 18th, 2008 2:39 am
Re: Inserting values into the database using a asp.net button click
 
Hi Dani,

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

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.

Aneesh_Argent Dec 18th, 2008 7:43 am
Re: Inserting values into the database using a asp.net button click
 
Try this :
DdlId.SelectedItem.Text;

Kusno Dec 19th, 2008 2:59 am
Re: Inserting values into the database using a asp.net button click
 
Hi, you still forgot for DropDownList

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


All times are GMT -4. The time now is 4:20 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC