C中條件查詢資料庫並顯示相應字段

2021-03-27 20:53:00 字數 4588 閱讀 6510

1樓:郭某人來此

你的意思是想獲得username的值:

你可以這樣:

使用datatable:

string sqltext=" select username form userinfo where userid = "xx""

private sqlconnection conn = new sqlconnection("連線字串");

datatable dt = null;

sql***mand *** = null;

sqldataadapter sda = null;

public datatable excutesqlquerytext(string sqltext)

這個方法返回的是乙個datatable 並且在datatable中的第一行就會是你想要的資料

string username=dt.rows[0]["username"];

這個username就會是你想要的資料了

2樓:小孟

簡單澀;

public string getnamebyid(int id)在外面呼叫方法;

string name=getnamebyid(id--想要查詢名字的id);

3樓:dou***歲月

select name from where id="";

textbox2.text=bll.executescalar(sql);

4樓:匿名使用者

你到底是想問什麼··

c#如何以資料庫的表中某乙個或幾個欄位為條件搜尋

5樓:匿名使用者

用 string.format();

例如再資料庫student表中查詢姓 "李" 的同學........

pubic void showinfo()",);

sqldatereader reader = null;

try}catch(exception ex)finally}

6樓:

sql拼接嘛,這雖然不優雅,但最省事,當然了,引數得先處理下,別帶特殊符號比如'-

sql="select * from table_name where 1=1";

if(tj1!="")

if(tj2!="")

if(tj3!="")

c#.***從資料庫中查詢出某錶中某行的某個字段值

7樓:不識台北路

sqlconnection con = new sqlconnection("***");//***為你的連線字串

sql***mand cmd = new sql***mand();//實體化sql***mand

cmd.connection=con;//為cmd的con***ion屬性賦值

cmd.***mandtext="select para from sys where id=@id"//查詢語句@id為引數

cmd.parameters.addwithvalue("@id","admin");//傳參

con.open();//開啟連線

string res=cmd.excutescalar().tostring();//獲取你需要的專結果

con.close();//關閉連線

話說上面那個

屬人的肯定執行不了,不信你試試看。

8樓:匿名使用者

string str="server=.;u;database="資料庫名";pwd="資料庫密

du碼zhi";

sqlconnection con = new sqlconnection(str);//***為dao你的連線字串

sql***mand cmd = new sql***mand();//實體化內sql***mand

cmd.connection=con;//為cmd的con***ion屬性賦值

cmd.***mandtext="select para from sys where id='admin'"//查詢語容句@id為引數

con.open();//開啟連線

string res=cmd.excutescalar().tostring();//獲取你需要的結果

con.close();//關閉連線

9樓:

connection conn=new connection();

string str="server=.;u;database="資料庫名";pwd="資料庫密碼

版";conn.open();

***mand cmd=new ***mand();

cmd(str,conn);

string str1="select para from sys where id='admin'";

string str2=cmd.excutescalre();

conn.close();

str2就是

權para的值;

c#如何查詢資料庫中同乙個欄位的幾個值?

10樓:匿名使用者

同一欄位的幾個值是什麼意思,有什麼特徵,可以用sql語句實現啊,如 select 欄位名 from 表名 where 條件,其中條件根據你要查詢的值來定,如用like,in等

c#程式設計**如何從資料庫中查詢並把查詢結果顯示在datagridview?

11樓:a九尾妖姬

最簡單的

寫乙個資料查詢類.然後呼叫xx.chaxun方法

sql = "select * from ***x";

datatable dt = xx.chaxun(sql);

datagridview1.datasource = dt;

記得將datagridview裡面的字段與表中的字段相關聯

dateset 或datatable或集合進行資料繫結,如有什麼問題,請繼續追問 private dataset ds = new dataset();

private sqldataadapter adapter = new sqldataadapter();//建立資料介面卡

sql***mand *** = new sql***mand("select teacguid, tea**ame as 姓名,teac*** as 性 別,teacsalary as 工資,teacremark as 備註 from teachers", dbhelper.con);

adapter.select***mand = ***;

adapter.fill(ds, "teachers");//將按照條件查出來的teachers表中資訊填充到ds中

this.datagridview1.datasource = ds.tables["teachers"]; 附上一段用dataset實現的**。

12樓:lj的淡

使用dateset  或datatable或集合進行數copy據繫結,如有什麼問題,請繼續追問  private dataset dt = new dataset();

private sqldataadapter adapter = new sqldataadapter();//建立資料介面卡

sql***mand *** = new sql***mand("select teacguid, tea**ame as 姓名,teac*** as 性     別,teacsalary as 工資,teacremark as 備註 from teachers", dbhelper.con);

adapter.select***mand = ***;

adapter.fill(dt, "teachers");//將按照條件查出來的teachers表中資訊填充到dt中

13樓:手機使用者

dateset 或datatable或集合進行資料copy

繫結,如有什麼問bai

du題,請繼續追問 private dataset ds = new dataset();

private sqldataadapter adapter = new sqldataadapter();//建立資料適配zhi器

sql***mand *** = new sql***mand("select teacguid, tea**ame as 姓名,teac*** as 性 別,teacsalary as 工資dao,teacremark as 備註 from teachers", dbhelper.con);

adapter.select***mand = ***;

adapter.fill(ds, "teachers");//將按照條件查出來的teachers表中資訊填充到ds中

this.datagridview1.datasource = ds.

tables["teachers"]; 附上一段用dataset實現的**,如果有疑問,請繼續追問,如果沒有,請採納,萬分感謝

C從資料庫中去到資料並顯示在label中

你用c 編碼的話,應該用的是vs,開發。在.中,label是有伺服器控制項的。取值極其簡單方便。方法 首先從工具箱裡拖出乙個label控制項放在.aspx頁中,然後在.cs檔案裡給this.label.text賦值。如this.label.text username username的值是從sql2...

c將資料庫查詢結果賦值到變數中,c 資料庫 怎麼把查詢到 賦值到乙個變數

會用ado.net執行這句sql,然後返回資料結果吧?然後因為你的這句sql只有一行一列的值,所以直接返回0行0列,或0行 count 列就好,如下 1int count convert.toint32 dataset.tables 0 rows 0 0 tostring 或 1 int count...

C如何把從資料庫查詢到的資料顯示在DataGridView中,求大神指教(急

將繫結 改為一下即可 sqlconnection sqlconnection1 new sqlconnection sql mand cmd new sql mand strsql,sqlconnection1 sqldataadapter sqldataadapter1 new sqldataad...