【发布时间】:2015-01-16 08:38:48
【问题描述】:
我在名为“Database”的数据库中创建了一个名为“Client”的表,但是当我尝试显示某个选择查询的结果时,它给了我错误
"错误 1 'System.Data.DataRow' 是一个 'type' 但被用作'variable'
private void button1_Click(object sender, EventArgs e)
{
try
{
string myConnection =
"datasource=localhost;port=3306;username=abc;password=xyz";
MySqlConnection myConn = new MySqlConnection(myConnection);
MySqlDataAdapter myDataAdapter = new MySqlDataAdapter();
myDataAdapter.SelectCommand = new MySqlCommand(
"select * from Database.Client", myConn);
MySqlCommandBuilder cb = new MySqlCommandBuilder(myDataAdapter);
myConn.Open();
// MessageBox.Show("Connected");
DataSet ds = new DataSet();
DataRow dr = new DataRow();
DataTable dt;
myDataAdapter.Fill(ds, "Client");
dt = ds.Tables["Client"];
dr = dt.Rows[0];
dg.DataSource = ds.Tables["Client"];
myConn.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
【问题讨论】:
-
异常在哪里引发?代码似乎没问题。
-
你在哪一行得到这个错误?查看您的代码,没有任何东西可以引发该异常。