亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

異常錯誤 ,請大俠幫忙瞧瞧

異常錯誤 ,請大俠幫忙瞧瞧

慕碼人8056858 2018-12-07 02:51:48
?????? private void button1_Click(object sender, EventArgs e)??????? {??????????? string uname;??????????? string upwd; ??????????? uname = textBox1.Text.ToString(); ??????????? upwd = textBox2.Text; ??????????? int num=1;??????????? int db;??????????? db = getDB(uname, upwd); ??????????? if (num == db)??????????? {??????????????? MessageBox.Show("全部成功", "好");??????????? }??????????? else ??????????? {??????????????? MessageBox.Show("NO", "好");??????????? } ??????? } ??????? public static int getDB(string uname,string upwd) ??????? {??????????? SqlConnection con = new SqlConnection("server=XPSP2USER;uid=sa;pwd=sasa;database=demoDB"); ??????????? con.Open(); ??????????? string sql = "select * from utable where id='"+uname+"'and pwd='"+upwd+"'"; ??????????? SqlCommand com = new SqlCommand(sql,con);??????????? ?????????? ??????????? ??????????? MessageBox.Show("數據庫連接成功","好的"); ?????????? int yz;?????????? try ?????????? {?????????????? yz = Convert.ToInt16(com.ExecuteScalar());????????????? ?????????????? } ?????????? catch(Exception e){?????????????? throw ;??? ?????????????? } ?????????? ??????????? con.Close(); ??????????? return yz;??????????? ??????? }
查看完整描述

1 回答

?
慕標5832272

TA貢獻1966條經驗 獲得超4個贊

yz = Convert.ToInt16(com.ExecuteScalar());

com.ExecuteScalar()這個是返回第一行第一列啊,現在估計返回的不是數字,所以轉成int出錯了。

把這個sql語句改下:

string sql = "select * from utable where id='"+uname+"'and pwd='"+upwd+"'";

改成:string sql = "select count(*) from utable where id='"+uname+"'and pwd='"+upwd+"'";

查看完整回答
反對 回復 2019-01-21
  • 1 回答
  • 0 關注
  • 588 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號