Link to home
Create AccountLog in
Avatar of intchauspe
intchauspe

asked on

SQL Insert with ASP.NET 2.0

Hi guys,

I have what I think is a pretty easy question.  I've just started using ASP and I'm trying to take the input from 2 text boxes and run an insert command when a button is pushed.    I have the text boxes set as parameters and the query seems to work but I need to know how to make it fire when the "add" button is pushed.  I assume I need to add some code to the click event of the button but everything I've tried so far isn't working.  

I already have a SqlDataSource that displays (selects) the current records  I also defined the insert command and the parameters.  how to I connect that button event to the insert command on the SqlDataSource?

 Can someone point me down the right path.
ASKER CERTIFIED SOLUTION
Avatar of craskin
craskin
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
dim strSql as string
strSql= me.SqlDataSource1.InsertCommand
strSql.Parameters.Add("@ParameterName", SqlDbType.VarChar).Value = TextBox1.Text
...

...

This is when you have an insert command generated along with your sqldatasource..

See if this works
Avatar of intchauspe
intchauspe

ASKER

Thanks Craskin - That worked Great.  I knew it should be simple. I was just a little foggy on the details. Thanks for putting me on the path!
Hi, I have a similar issue, although I have a stored procedure ready to accept parameters for an insert based on what I assume would be the onclick event of my button.

As I am very new to ASP.Net 2.0, any help anyone has on this issue would be a great help.