I am developing a form in VB.Net and ASP.Net that enables a user to grab data from a SQL Server 2005 Express database and display the data on the screen depending on the search criteria that they provide.
What would be the best way to go about doing this?
Well a suser enters a code in to a textbox and clicks on a button to retrieve the info for that code from the backend database and display it up on the screen.
Would I be right, therefore, in assuming that I need to set up a connection string to tell the program where the database is, the table its looking for and a select statement WHERE the code provided in the text box = the code that is in the table??
If so, what sort of details would I need to provide in the connection string?
Dim mycn As SqlConnection
Dim strCnn As String = Persist Security Info=False; Data Source=ServerName;UID=userId;PWD=Password ;Initial Catalog=DBName; mycn= New SqlConnection(strCnn)
Dim comm As New SqlCommand("your Query", mycn)
comm.CommandType = CommandType.StoredProcedure
Dim da As New SqlDataAdapter(comm)
Dim ds As New DataSet
I have now put the ccode in to my program as above.
My sql connection variable is underlined saying that it is being used before being assigned a value.
Dim sqlConn As SqlConnection
Dim sqlCmd As New SqlClient.SqlCommand
Dim sqlReader As SqlDataReader
If TextBox1.Text = "" Then
MsgBox("A centre code needs to be provided...")
If TextBox1.Text <> "" Then
'Telling the system the location of the database.
sqlConn.ConnectionString = "server=server;Initial Catalog=dbname;Trusted_Connection=yes"
'Here we are opening the connection to the database.
'This is to say that sqlCmd is a stored procedure.
sqlCmd.CommandType = CommandType.StoredProcedure
'This is creating the command to execute the stored procedure based on the information given in the connection string.
sqlCmd = sqlConn.CreateCommand
sqlCmd.CommandText = "exec dbo.GetAllInformation '" & TextBox1.Text & "' "