R
Rob Meade
Hi all,
Haven't really played with these beasts very much - so probably my fault as
to why its not working.
I found an example of some code here -
http://aspnet.4guysfromrolla.com/articles/040502-1.aspx - and then changed
the relevant parts for my application - below is my code, when it runs I
enter some search criteria into a text box - I have run the sql statement
seperately to ensure that it does indeed return results and it does - 1
row - yet when my code runs I get nothing - no errors which is good - but no
data either! Any help with this would be appreciated.
Code:
' Declare variables
Dim strSearchConsultant As String
Dim objConnection As SqlConnection
Dim objCommand As SqlCommand
Dim strSQL As String
strSearchConsultant = txtSearchConsultant.Text
' Create and open our database connection
objConnection = New
SqlConnection(ConfigurationSettings.GetConfig("appSettings")("connStringBris
tolPDD"))
objConnection.Open()
' Create command object
objCommand = New SqlCommand
objCommand.Connection = objConnection
' Generate sql statement
strSQL = "SELECT CrfDHANationalCode, CrfCode, CrfExpansion FROM
viewCDSConsultants "
strSQL += "WHERE UPPER(CrfCode) LIKE '%@ConsultantCode%' OR
UPPER(CrfExpansion) LIKE '%@ConsultantName%'"
' Add parameters
objCommand.Parameters.Add("@ConsultantCode",
strSearchConsultant.ToUpper)
objCommand.Parameters.Add("@ConsultantName",
strSearchConsultant.ToUpper)
' Set our command object
objCommand.CommandText = strSQL
' Set the datagrid's datasource to the datareader and databind
dgSearchConsultantResults.DataSource =
objCommand.ExecuteReader(CommandBehavior.CloseConnection)
dgSearchConsultantResults.DataBind()
Regards
Rob
Haven't really played with these beasts very much - so probably my fault as
to why its not working.
I found an example of some code here -
http://aspnet.4guysfromrolla.com/articles/040502-1.aspx - and then changed
the relevant parts for my application - below is my code, when it runs I
enter some search criteria into a text box - I have run the sql statement
seperately to ensure that it does indeed return results and it does - 1
row - yet when my code runs I get nothing - no errors which is good - but no
data either! Any help with this would be appreciated.
Code:
' Declare variables
Dim strSearchConsultant As String
Dim objConnection As SqlConnection
Dim objCommand As SqlCommand
Dim strSQL As String
strSearchConsultant = txtSearchConsultant.Text
' Create and open our database connection
objConnection = New
SqlConnection(ConfigurationSettings.GetConfig("appSettings")("connStringBris
tolPDD"))
objConnection.Open()
' Create command object
objCommand = New SqlCommand
objCommand.Connection = objConnection
' Generate sql statement
strSQL = "SELECT CrfDHANationalCode, CrfCode, CrfExpansion FROM
viewCDSConsultants "
strSQL += "WHERE UPPER(CrfCode) LIKE '%@ConsultantCode%' OR
UPPER(CrfExpansion) LIKE '%@ConsultantName%'"
' Add parameters
objCommand.Parameters.Add("@ConsultantCode",
strSearchConsultant.ToUpper)
objCommand.Parameters.Add("@ConsultantName",
strSearchConsultant.ToUpper)
' Set our command object
objCommand.CommandText = strSQL
' Set the datagrid's datasource to the datareader and databind
dgSearchConsultantResults.DataSource =
objCommand.ExecuteReader(CommandBehavior.CloseConnection)
dgSearchConsultantResults.DataBind()
Regards
Rob