简体   繁体   English

找不到表0

[英]Cannot find table 0

I'm getting this error when I try to insert into table pay_cheque any help 当我尝试向表pay_cheque插入任何帮助时出现此错误

private void btnadd_Click(object sender, EventArgs e)
{

    string s = "insert into pay_cheque values('Sai','Sai','Sai','Sai','10.2','1989/2/3','Sai')";
    SqlConnection con = new SqlConnection("server=.;Data Source=.;Initial Catalog=Book;Integrated Security=True");
    SqlDataAdapter da = new SqlDataAdapter(s, con);
    DataSet ds = new DataSet();
    da.Fill(ds, "x");
    dataGridView1.DataSource = ds.Tables[0];
}

The Fill method will retrieve data of a query and fill a dataset. Fill方法将检索查询的数据并填充数据集。 However, you are not using a query statement. 但是,您没有使用查询语句。 You can only do that with a SELECT statement, then you can retrieve the data and fill a dataset. 您只能使用SELECT语句执行此操作,然后才能检索数据并填充数据集。

To retrieve the data, use a SELECT statement based on the primary key after you have inserted it. 要检索数据,请在插入后基于主键使用SELECT语句。 Even though doing so is pretty useless in my opinion. 即使这样做在我看来也毫无用处。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM