Imports System.Windows.Forms

Partial Class ExisitingApplication

Inherits System.Web.UI.Page

Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearch.Click

  If Me.txtLastN.Text = "" Then

     Dim erMsg As Windows.Forms.DialogResult = MessageBox.Show("Must enter Last Name.", "Search", MessageBoxButtons.OK)

  End If

  'Define connection string with datasource
  Dim str As String = ConfigurationManager.ConnectionStrings("SqlDataSource1").ToString

  'Define sql statement to be used
  Dim strUSRACCESS As String = "SELECT FirstName, LastName, SSN from tblMAGIapplications where (FirstName = @FirstName and LastName = @LastName) or (SSN = @SSN)  "

  'Define sql connection using connection string defined above
  Dim USRconn1 As New Data.SqlClient.SqlConnection(str)

  'Define the compelete sql statement with connection and sql string
  Dim CMD As New Data.SqlClient.SqlCommand(strUSRACCESS, USRconn1)

  'Define reader for sql information returned
  Dim drUSR As Data.SqlClient.SqlDataReader = (0)

  'Open SQL Connection
  USRconn1.Open()

  'Dim number As Integer
  'If Int32.TryParse(Me.txtSS.Text, number) = True Then
  'CMD.Parameters.AddWithValue("@SSN", number)
  'Else
  'CMD.Parameters.AddWithValue("@SSN", 0)
  'End If

  'Add parameters
  CMD.Parameters.AddWithValue("@FirstName", Me.txtFirstN.Text)
  CMD.Parameters.AddWithValue("@LastName", Me.txtLastN.Text)
  'CMD.Parameters.AddWithValue("@SSN", Int32.TryParse(Me.TextBox1.Text, number))
  ''SqlDataSource1.DataBind()
  ''Me.GridView1.DataSourceID = SqlDataSource1
  GridView1.DataSourceID = String.Empty
  GridView1.DataBind()
  USRconn1.Close()

End Sub
End Class

Edited 2 Years Ago by JorgeM: moved to vb.net since this code appears to be for windows.forms

What help do you need. all you provided was some sample code. No detailed question, no error information??

Comments
I'm not getting an error. Nothing happens after I hit the search button. This is the code I'm using for my application. Here's the background on the application. The user will enter data on one page and submit. The data is stored in my table I created in

I'm not getting an error. Nothing happens after I hit the search button. This is the code I'm using for my application. Here's the background on the application. The user will enter data on one page and submit. The data is stored in my table I created in mircosoft sql-database. The user then should be able to go back search with last name, first name, or SSN it should retreived that data and display in a gridview that also allows user to edit, delete, and re-save.

Did you copy this code from somewhere? it seems to be incomplete and doesnt seem to be correct.

For example, without actually validating your code and just briefly scanning it, I see that you are building a SQL query, but you dont seem to execute it, then towards the bottom you are trying to bind something to the gridview, but that doesnt make sense regarding your the top portion of the code.

I wrote it. The bind part came from trying different suggestions after researching different websites. Can you advise me with what I should do? What I need to add or delete? Thank you for responding.

This article has been dead for over six months. Start a new discussion instead.