DataReader & Placeholder
-
Hello Im using: SQL Server 2005 - VS 2008 Im trying to read data with using DataReader. when I want to replace my data with variable there is an error :
Must declare the scalar variable "@G#".
Behind code :objConnection.Open(); string query = "Select * From goods where G#=@G#"; objDataAdapter.SelectCommand.Parameters.AddWithValue("@G",Textbox.Text); using (reader = new SqlCommand(query, objConnection).ExecuteReader()) { if (reader.HasRows) { while (reader.Read()) { // Do sth } } }
TIA :) -
Hello Im using: SQL Server 2005 - VS 2008 Im trying to read data with using DataReader. when I want to replace my data with variable there is an error :
Must declare the scalar variable "@G#".
Behind code :objConnection.Open(); string query = "Select * From goods where G#=@G#"; objDataAdapter.SelectCommand.Parameters.AddWithValue("@G",Textbox.Text); using (reader = new SqlCommand(query, objConnection).ExecuteReader()) { if (reader.HasRows) { while (reader.Read()) { // Do sth } } }
TIA :)comp_j wrote:
string query = "Select * From goods where G#=@G#";
What was that ? G# is your field name ?
comp_j wrote:
@G#"
You can't use over here. You need to used
'@'
when you are using parameter only.Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you. View My Latest Article
-
comp_j wrote:
string query = "Select * From goods where G#=@G#";
What was that ? G# is your field name ?
comp_j wrote:
@G#"
You can't use over here. You need to used
'@'
when you are using parameter only.Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you. View My Latest Article
-
Hello Im using: SQL Server 2005 - VS 2008 Im trying to read data with using DataReader. when I want to replace my data with variable there is an error :
Must declare the scalar variable "@G#".
Behind code :objConnection.Open(); string query = "Select * From goods where G#=@G#"; objDataAdapter.SelectCommand.Parameters.AddWithValue("@G",Textbox.Text); using (reader = new SqlCommand(query, objConnection).ExecuteReader()) { if (reader.HasRows) { while (reader.Read()) { // Do sth } } }
TIA :)using(SqlConnection objConnection = new SqlConnection) { objConnection.Open(); string query = "Select * From goods where G#=@GParam"; using (SqlCommand command = new SqlCommand(query, objConnection)) { command.Parameters.Add(new SqlParameter("@GParam", SqlDataType.yourtype, value)); // Do replace with your value here. SqlDataReader reader = command.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { // Do sth } } } }
Hope this works... :rose::rose:Abhishek Sur
My Latest Articles **Create CLR objects in SQL Server 2005 C# Uncommon Keywords Read/Write Excel using OleDB
**Don't forget to click "Good Answer" if you like the post
-
using(SqlConnection objConnection = new SqlConnection) { objConnection.Open(); string query = "Select * From goods where G#=@GParam"; using (SqlCommand command = new SqlCommand(query, objConnection)) { command.Parameters.Add(new SqlParameter("@GParam", SqlDataType.yourtype, value)); // Do replace with your value here. SqlDataReader reader = command.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { // Do sth } } } }
Hope this works... :rose::rose:Abhishek Sur
My Latest Articles **Create CLR objects in SQL Server 2005 C# Uncommon Keywords Read/Write Excel using OleDB
**Don't forget to click "Good Answer" if you like the post
-
you are most welcome friend. :thumbsup::thumbsup:
Abhishek Sur
My Latest Articles **Create CLR objects in SQL Server 2005 C# Uncommon Keywords Read/Write Excel using OleDB
**Don't forget to click "Good Answer" if you like t