Monday, March 26, 2012

Passing values into SQL Server

Hi: I create two textboxes and a button and try to pass values from the
textboxes into SQL Server by using Save Button Can any one please tell
me do i write some code on save button or i bind the textbox with the
SQL Server fields as i bind the fields in VB.NET
Thanks,Few controls have automagic binding in a web app. Try something like this:
Dim textbox1Value as TextBox1.Text
Dim textbox2Value as TextBox2.Text
Dim sql as String = "INSERT INTO SomeTable VALUES (@.Val1, @.Val2)"
Dim conn As New SqlConnection("Your Connection string Here")
Dim cmd as New SqlCommand(sql, conn)
Dim param1 As new SqlParameter("@.Val1", SqlDbType.VarChar, 50)
Dim param2 As new SqlParameter("@.Val2", SqlDbType.VarChar, 50)
cmd.Parameters.Add(param1)
cmd.Parameters.Add(param2)
Try
conn.Open()
cmd.ExecuteNonQuery()
Catch ex As Exception
'Not sure how you want to handle exceptions
Finally
conn.Dispose()
End Try
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com
****************************************
****
Think outside the box!
****************************************
****
<colleen1980@.gmail.com> wrote in message
news:1165317810.925443.207280@.79g2000cws.googlegroups.com...
> Hi: I create two textboxes and a button and try to pass values from the
> textboxes into SQL Server by using Save Button Can any one please tell
> me do i write some code on save button or i bind the textbox with the
> SQL Server fields as i bind the fields in VB.NET
> Thanks,
>

0 comments:

Post a Comment