当前上下文中不存在名称 “strcon”

SqlConnection conn = new SqlConnection(strcon);

SqlConnection conn = new SqlConnection(strcon);
string sqlStrSelect = "select[BookID],[ISBN],[BookName],[Publisher],[Price],[LTime]from[RBL]where[ReaderID]='" + textBox1.Text.Trim() + "'";
try
{
SqlDataAdapter adapter = new SqlDataAdapter(sqlStrSelect, conn);
DataSet dstable = new DataSet();
adapter.Fill(dstable, "testTable");
dataGridView1.DataSource = dstable.Tables["testTable"];//表testTable为dataGridView1数据源
dataGridView1.Show();
}
catch (Exception ex)
{ MessageBox.Show(ex.Message); }
finally
{ conn.Close(); }
当前上下文中不存在“strcon”
你这个strcon应该是一个数据库连接的字符串,而你没有声明运氏这个string
你在 SqlConnection conn = new SqlConnection(strcon);这段代码上加上这个旁厅散
string strcon="";//里面写你的数伏亩据库连接字符串就可以了
strcon是什么东西?你没有声明或者定义怎么能直接用呢?
就比如你在第胡察一句里面定义了conn,那么后面你就可以用你了,但基做宽是strcon,你根本就没有声明。
LZ如果有时间,应该先看看语法书。貌似你没有搏亮编程基础啊。
没有声明变量strcon
在SqlConnection conn = new SqlConnection(strcon);
之前加亮掘上咐蔽string strcon="数据库连接字敬简核符串";
在你的这个项目中strcon应该是链接数据库的字符串。你只需要加上就可以了
没声明strcon