C datatable讀取資料庫

2022-03-15 02:52:52 字數 1368 閱讀 1161

1樓:正怒月神

datatable dtb = null;

string sql = "select class from table1 where name = '張三' ";

dtb = db.getdatatable(db.form,sql);

string dtbstr=dtb.rows[行下標][列下標].tostring(); //兩種寫法,獲得datatable中的某行某列的值

string dtbstr1=dtb.rows[行下標]["列名"].tostring();

2樓:薛寶魁

using system.data.sqlclient;

public sqlconnection con = new sqlconnection("data source=suibian\\sqlexpress;initial catalog=myschool_new;integrated security=true");

3樓:匿名使用者

dtb.rows[0]["class"]就可以取出class的值了

c#怎麼將datatable中的資料讀到textbox中

4樓:匿名使用者

我們按步驟來說吧:

首先,做窗體的載入事件

然後,在事件中寫連線資料庫的**,以及用datareader講資料庫表中你需要的記錄讀取出來

最後,將你讀取的資訊賦值給對應的textbox的text屬性就ok了希望能解決你的問題

5樓:匿名使用者

datatable dt=new datatable();

如果dt中有值則這樣讀

textbox1.text= dt.rows[0]["列名"].tostring();//0代表第一行,以此類推

6樓:匿名使用者

我們按步驟來說吧:

首先,在事件中寫連線資料庫的**,以及用datareader將資料庫中你需要的記錄讀取出來

然後,將你讀取的資訊新增到乙個檔案中,

最後,將你檔案中訪問的資訊,按照textbox的需求讀取出來顯示到對應的地方。

希望能解決你的問題

c#中怎麼用for迴圈遍歷datatable中的資料?

7樓:然後去遠足

for (int i = 0; i < datatable.rows.count; i++) }

c# 從資料庫讀取資料

如何讀取csv檔案到datatable中,然後存到資料庫

c從資料庫讀取image到picturebox中

試試下面的 bytebarrimage byte 獲取的資料庫中對應欄位的值memorystream ms new memorystream barrimage image image image.formstream ms 獲取到 的二進位製流後再轉成 格式 c s端還是b s端,處理手段大不相同...

php讀取mysql資料庫的內容後顯示為亂碼,中文變成問號怎

換成utf8肯定不行,因為是問號,肯定不是三位元組到兩位元組 的問題,而是和拉丁1有關,因為問號是不可能轉換的意思 失敗了,解決 你需要 按資料流入的程式再配置好,再原路返回,再換重新建庫,匯入 ok 順便說一下,出的分太少了 hostname conn localhost database con...

資料庫查詢,資料庫查詢語句

try this,should be fine select sn,result,ttimefrom select sn,result,ttimefrom tab t1 where not exists select 1 from tab where sn t1.sn and ttime t1.tt...