1樓:碎碎x惗
1.方法:
首先需要建好資料庫,在資料庫的表中有你所說的學號,姓名,地址等資訊,既然你會連線資料庫了這些就不多說了。然後需要建立一個布林型的驗證方法,用sqldatareader從資料庫中讀取學號的資訊,判斷學號是否存在,如果存在就把資料庫中的姓名和地址資訊取出來給gridview控制元件,如果不存在的話則彈出提示錯誤資訊。
2.**:
其中id是指學號,name指姓名,address指地址,student_db是資料庫中表的名字。
sqlconnection con;
sql***mand cmd;
sqlconnectionstringbuilder scsb = new oracleconnectionstringbuilder();
public bool yanzheng(string id)
protected void button1_click(object sender, eventargs e)
else
;gridview1.databind();
con.close(); }}
2樓:索利丘拉
string tex=textbox1.text.tostring().trim; // 取到textbox1中的數值
label1.text=tex; //顯示給label1
string str="連線字串
"; //連線字串
sqlconnection an=new sqlconnection (str);
an.open();
string sql=string.format("select * from table where 條件=",tex); // sql語句
sql***mand md = new sql***mand(sql, an);
sqldatareader od = md.executereader();
while (od.read())
an.closed();
3樓:匿名使用者
寫一個獲得姓名,地址的方法,引數是你textbox1輸入的數,方法的返回值為datbale或者ilist都可以,然後就賦值到lable1和lable2上
4樓:呵呵呵呵呵呵
會連資料庫,那會讀從資料庫裡取出來的資料嗎?如果會的話直接將值賦給label就行了
c# 讀取sql server中的某個資料 顯示在label1中
5樓:風的角逐
樓主只給的只是連線字串,還有開啟連線、取出資料、關閉連線、放進label1還有4步,還有就是一行資料放進label1最好合並一個欄位或者使用datagridview顯示完整一行
怎麼樣把從sqlserver查詢出來的結果顯示在指定的label上?我是用c#寫的,求詳細**??
6樓:匿名使用者
sqlconnection con = new sqlconnection(「連線資料庫的字串」);
string sql = "select description from tab_pictype";
sql***mand sqlcmd = new sql***mand(sql, con);
sqldatareader dr = sqlcmd.executereader();
while (dr.read()) //讀取資訊
con.close();
7樓:匿名使用者
首先不明白你為什
麼要顯示在label上,這麼多ado的控制元件,比如gridview等等,你為什麼不用?如果一定要用label,看你是想顯示什麼?想顯示某個欄位的某個值,那簡單,從dataset中直接把這個值取出來,label1.
text = "你取得的值";
8樓:匿名使用者
string sqlconnection = new sqlconnection("連線字串");
sql***mand cmd=new sql***mand("查詢語句",conn);
conn.open();
sqldatareader sdr = cmmd.executereader();
if (sdr.read())
sql 語句: string sql="select * from tablea where 產品分類='"+this.textbox1.text+"'";
9樓:匿名使用者
問題都有那麼點糾結,指定在label上?不理解?
c#中如何在label.text上顯示sql資料庫裡的某一個值
10樓:匿名使用者
sqlconnection sqlconn = new sqlconnection();
sqlconn.connectionstring = "";
sqlconn.open();
sql***mand cmd = sqlconn.create***mand();
cmd.***mandtext = "select 職務 from 使用者資訊 where 賬號 = '7'";
sqldatareader reader = cmd.executereader();
reader.read();
string temp_role = reader.getstring(0);
sqlconn.close();
label1.text = temp_role;
具體的sql語句,連線字元竄你自己對應著改,其他應該不會報錯的,結果就是你要的
11樓:
後臺呼叫 資料庫方法查詢需要的值 ,返回這個值,
例子:string fd=select id from tb_login where id='***';
label.text=fd;
12樓:匿名使用者
上面**太麻煩
多餘了.......
string connectionstring=******xx; //自己定義
sqlconnection myconn = new sqlconnection(connectionstring);
myconn.open();
string mysql = "select id from tb_login where id='***'";
sql***mand mycmd = new sql***mand(mysql, myconn);
sqldatareader myreader = mycmd.executereader();
myreader.read();
label.text=myreader["id"].tostring();
.......
13樓:匿名使用者
讀資料庫,寫個table出來。看第一行第一個的值就是要找的
14樓:匿名使用者
sqlconnection conne = new sqlconnection("data source = ***x; initial catalog=***x ; user id=sa ; password = ***x");
public datatable querytodatatable(string sqlcondition)
private void btnkkk_click(object sender, eventargs e)
conne.close();}
15樓:從沒覺得累
定義一個全域性變數,比如全域性變數是f
在label.text寫<%=f%>
16樓:匿名使用者
怎麼沒有關閉資料庫?
c#如何從sql資料庫中取資料,然後顯示到label中
17樓:匿名使用者
if (datareader.read()) }
在這裡下斷點,看看這裡得到的sign是不是你要的資料。
18樓:匿名使用者
設斷點除錯過沒? 你確定獲取到了資料庫中的資料?
c# 怎樣將查詢到符合條件的 條數 顯示在 label上
19樓:匿名使用者
this.lable.text="總共"+dt.rows.count+「條記錄」
c#.***中如何將資料庫中的內容顯示到label中
20樓:給世界一些震撼
label news = this.controls["new" + i.tostring()] as label;
錯在這句話上:
錯誤 1 與「system.web.ui.controlcollection.this[int]」最匹配的過載方法具有一些無效引數
this.controls這裡面只能寫int型別的,不能有其它型別。
21樓:馮益斌
要顯示列表類資訊,推薦使用gridview,可以後臺動態繫結,非常方便。
用c怎麼以連線SQLServer
首先新增引用名稱空間using system.data.sqlclient 然後建立連線 string constr server database yourdb uid sa pwd sa 這個注意一般寫在配置檔案中額 先用sqlconnection建個連線 然後建立sql mand物件 利用 s...
如何連線sqlserver
有兩種方法.一種是 connectionptr pmyconnect null pmyconnect.createinstance uuidof connection bstr t strconnect provider sqloledb server server name database da...
C語言 從鍵盤上輸入一行字元,將其中的大寫字母改成小寫字母后
include include using namespace std void main cout 請輸入一組字串 string line cin line int i for i 0 i a line i z line i line i a a cout 轉換後的字串逆序輸出為 內 for i ...