我正在使用SQL Server Ce并尝试获取AuthorID from table Author where fName + ' ' + lName = textBox3.text
查询必须返回存储在DataTable中的2个作者ID(2行),但我只得到一行只有第一个作者ID
public static DataTable Select(string sql)
{
SqlCeDataAdapter DataAdapter = new SqlCeDataAdapter(sql, conn);
DataTable dt = new DataTable();
DataAdapter.Fill(dt);
return dt;
}
private void pictureBox1_Click(object sender, EventArgs e)
{
string[] authors = textBox6.Text.Split(',');
DataTable dt;
string sql = @"select AuthorID from Author where ((fName + ' ' + lName = '" + authors[0] + @"')";
for (int i = 0; i < authors.Length; i++)
{
if (i != authors.Length - 1)
{
sql += @"OR (fName + ' ' + lName = '" + authors[++i] + @"'))";
}
}
dt = Form1.Select(sql);
dataGridView1.DataSource = dt;
for (int i = 0; i < authors.Length; i++)
{
Form1.Query(@"insert into Book_Author ([ISBN], AuthorID) values (" + ISBN + ", " + dt.Rows[i]["AuthorID"] + ")");
}
任何帮助??