net 缺少對(duì)象或列名,或者對(duì)象或列名為空。對(duì)于 SELECT INTO 語句,請(qǐng)確保每列均具有名稱。對(duì)于其他語句string selecsql="select count(*) from twhd where title="+TextBox1.Text.ToCharArray();string connstr=@"Data Source=WWW-0C1C21770A3\SQLEXPRESS;Initial Catalog=xtez;Integrated Security=True";SqlConnection conn=new SqlConnection(connstr);conn.Open();SqlCommand cmd1=new SqlCommand (selecsql,conn);int count= Convert.ToInt32(cmd1.ExecuteScalar());當(dāng)執(zhí)行到最后一行的時(shí)候就出現(xiàn)了上面說的錯(cuò)誤,請(qǐng)高人指教一下,我就這么多分了全部拿出來
2 回答

莫回?zé)o
TA貢獻(xiàn)1865條經(jīng)驗(yàn) 獲得超7個(gè)贊
第一:請(qǐng)你將 string selecsql="select count(*) from twhd where title="+TextBox1.Text.ToCharArray();
換成
string selecsql=String.Format("select count(*) from twhd where title='{0}'",TextBox1.Text.ToString());
第二:請(qǐng)你確認(rèn)在 int count= Convert.ToInt32(cmd1.ExecuteScalar());
該條語句執(zhí)行前 TextBox1.Text 有值
如果這段代碼是 啟動(dòng)時(shí)就執(zhí)行,并且 TextBox1.Text 沒有賦初值 或者初值不是數(shù)據(jù)庫中的字段,就可能會(huì)出現(xiàn)以上錯(cuò)誤提示
- 2 回答
- 0 關(guān)注
- 638 瀏覽
添加回答
舉報(bào)
0/150
提交
取消