1
我有從的connectionString將數據傳送給listBoxDat按鈕代碼:沒有重載方法「獲得字符串」取0參數
private void btnClick_Click(object sender, RoutedEventArgs e)
{
tbTitle.Text = "ADO.Net";
listBoxData.Background = Brushes.LemonChiffon;
string cs = ConfigurationManager.ConnectionStrings["crams"].ConnectionString;
List<string> titles = new List<string>();
using (SqlConnection conn = new SqlConnection(cs))
{
conn.Open();
SqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "Select filenum FROM dbo.Complaint";
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
titles.Add(reader.GetString());
}
listBoxData.ItemsSource = titles;
}
}
我的錯誤列表口口聲聲說有對方法,沒有超載「GET sTring'需要0個參數。我不確定這是什麼意思!
想象一下你的查詢是 「選擇FILENUM,文件名,filetitle FROM dbo.Complaint」(假設你有三列)......然後一個應該'reader.GetString()'得到,如果你不告訴它哪一個? –