How to pass textbox value to Sql Query?

How to pass textbox value to Sql Query?

Just Drag and drop one Textbox control to your page.Click The Textbox then go to property window,Set Auto postback to True.

Imports System.Data.SqlClient
Imports System.Data
Partial Class _Default
Inherits System.Web.UI.Page
Dim con As SqlConnection
Dim cmd As SqlCommand
Dim strusername As String = String.Empty
Protected Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
con = New SqlConnection(("server=ServerName;database=DataBaseName;uid=userid;pwd=password;"))
cmd = New SqlCommand("select count(*) from Tablename where Username='" & TextBox1.Text & "'", con)
strusername = cmd.ExecuteScalar
If strusername <> "0" Then
MsgBox("UserName Already Exists")
' Response.Redirect("Default2.aspx")
End If
End Sub
End Class

Related Articles

More articles: Pass value to query SQL query


No responses found. Be the first to comment...

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: