From the title you may know that I cannot get the result when I query from sql database.
Here is my code :
public string Summon(int Input1)
{
SqlDataAdapter dbadapter = null;
DataSet returnDS = new DataSet();
using (SqlConnection dbconn = new SqlConnection(
"DatabaseConnection"))
{
SqlCommand cmd = new SqlCommand();
//string sqlQuery = "select * from SUMMON";
string sqlQuery = "select * from SUMMON where ic_no=@Input1";
cmd.CommandText = sqlQuery;
cmd.Connection = dbconn;
dbadapter = new SqlDataAdapter(cmd);
dbadapter.Fill(returnDS);
}
return returnDS.GetXml();
}
Then I get this exception :-
System.Data.SqlClient.SqlException: Must declare the scalar variable "@Input1".
You need to add a parameter named @Input1 to cmd:
This article explains how to use parameters with data adaptors.