here's what you can use:
// conn and reader declared outside try
// block for visibility in finally block
SqlConnection conn = null;
SqlDataReader reader = null;
try
{
string connstr = ConfigurationManager.ConnectionStrings["UnityConnectionString"].ToString();
// instantiate and open connection
conn = new
SqlConnection(connstr);
conn.Open();
// 1. declare command object with parameter
SqlCommand cmd = new SqlCommand(
"Select * from LG_006_CLCARD WHERE DEFINITION_= @DEF", conn);
//assuming your table in the database is indeed called 'DEFINITION_'
// 2. define parameters used in command object
SqlParameter param = new SqlParameter();
param.ParameterName = "@DEF";
param.Value = txtAccountCode.Text;
// 3. add new parameter to command object
cmd.Parameters.Add(param);
// get data stream
reader = cmd.ExecuteReader();
// write each record
while(reader.Read())
{
//Response.Write("{0}, {1}",
// reader["column1"],
// reader["column1"]);
Label6.Text = txtAccountCode.Text; //will display the value in the last record if there are multiple rows found for the select criteria
}
//GridView1.DataSource = reader;
//GridView1.DataBind();
}
finally
{
// close reader
if (reader != null)
{
reader.Close();
}
// close connection
if (conn != null)
{
conn.Close();
}
}
you don't need the gridview to simply test a select, step through the while(reader.Read()) loop or let it write to the label
here's a link that might help: http://www.csharp-station.com/Tutorials/AdoDotNet/Lesson06.aspx
besides, there are many tutorials on this site itself that might help you work your way up.http://www.asp.net/learn/data-access/