我正在尝试在c#中执行sql查询并将结果存储在DataTable
变量中。然后我想从特定行获取值。这是我的代码。
string query = "select * from Deptment where Dname=@Dname";
con.Open();
SqlCommand cmd = new SqlCommand(query, con);
cmd.Parameters.AddWithValue("@Dname", comboBox1.SelectedText);
SqlDataReader dr = cmd.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(dr);
textBox2.Text = dt.Rows[0][0].ToString();
Dept_name.Text = dt.Rows[0][1].ToString();
textBox1.Text = dt.Rows[0][2].ToString();
No_of_Employees.Text = dt.Rows[0][3].ToString();
Dept_discription.Text = dt.Rows[0][4].ToString();
con.Close();
但是我收到了这个错误:
位置0没有行。
答案 0 :(得分:1)
显然你没有结果。要避免此异常,请添加检查
dt.Rows[0]["Name"]
如果索引值如- (UIImage *)imageFromVideoURL:(NSURL *)contentURL {
AVAsset *asset = [AVAsset assetWithURL:contentURL];
// Get thumbnail at the very start of the video
CMTime thumbnailTime = [asset duration];
thumbnailTime.value = 25;
// Get image from the video at the given time
AVAssetImageGenerator *imageGenerator = [[AVAssetImageGenerator alloc] initWithAsset:asset];
CGImageRef imageRef = [imageGenerator copyCGImageAtTime:thumbnailTime actualTime:NULL error:NULL];
UIImage *thumbnail = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
return thumbnail;
}
,我会使用列名。当您更改表结构时,这会导致错误。