如何用C將textBox資料寫入SQL Server資料表

2021-04-01 08:14:29 字數 4473 閱讀 5785

1樓:何苦庸人自擾呢

這個錯誤提示很清晰了啊,你沒有寫值到number列啊,看一下你的stu表的number列設計的是什麼資料型別,insert時寫相應資料型別的值到number列試試。

2樓:匿名使用者

你的資料表有空值約束,不允許插入空資料。

所以你需要在執行sql前進行檢查

if(stu_name.length<1 || stu_age.length<1)

return;

另外,你需要處理特殊字元

stu_name=stu_name.replace("'","''");

stu_age=stu_age.replace("'","''");

否則資料庫接收特殊字元也會報錯。

3樓:匿名使用者

提示的不是很清楚了,你的資料庫的number欄位在資料庫裡設定的不允許為空,那你在插入時就需要指定一個值給number了。

4樓:匿名使用者

錯誤是說插入空值在number 這個列不允許空。

c#中怎麼將textbox中的資料加入sql表中..

5樓:匿名使用者

更改你的sql語句:insert into books (欄位

名一,欄位名二,欄位名三) values (『值一』,'值二',『值三』)其中, 欄位名錶示資料庫中的列, 值代表你要插入的資料, 如果你想將一個文字框中的值插入資料庫, 則將 值 更改為 文字框名.text。-------------以上為一層 三層等也是一樣, 在呼叫方法的時候將 文字框名.

text放到相對應的位置即可

6樓:匿名使用者

//例子如下:oledbconnection conn = new oledbconnection(" provider=microsoft.jet.

oledb.4.0;data source=school.

mdb"); string sql = "insert into students(studentno,studentname,***,birthday,native,address) values('" +

txtno.text + "','" + txtname.text + "','" + txt***.

text + "','" + datetime.parse(txtbirthday.text) + "','" + txtnative.

text + "','" + txtaddress.text + "')"; try

}catch (exception ex)finally

在用c#做窗體設計時,怎麼把textbox中的資訊新增到sql資料庫的表中

7樓:匿名使用者

先雙擊註冊按鈕 然後進到後臺**區,先判斷非空 然後再獲取使用者名稱 到資料庫去查詢

是否存在 要是存在就提示已存在 不存在就執行新增方法。

//這個是驗證非空

public string validate()

else if (this.txtpassword.text.trim()=="")

else if(....)

else

}//這個是按鈕的事件

protected void btnregister_click(object sender, eventargs e)

else

}else

}else

}pubic bool usernamei***ist(string name)

一般情況重置的功能就是將文字框清空的 並不是你說的刪除的功能

你要是真的想做成那樣也是可以的。具體的就是從資料庫查詢你最新新增 的一條資訊 然後刪除就ok了 **是手打的 有沒有錯誤的 我不是很清楚 但是裡面的有些引數 你自己得看看跟你寫的肯定是不一樣的 所以 你得更改。 這個應該是最詳細的了 要是不給分 那我就白忙活了........

c#怎麼把文字框中的資料寫到sql資料庫中

8樓:匿名使用者

我不知道你用的什麼結構 是cs結構還是bs結構

但對於c#語言的開發環境來說 都差不多

就是前臺顯示的是文字框 後臺取得文字框的id 然後以"."的方式獲取文字框的內容

例如:asp.*** 文字框名為

後臺.cs檔案中 string str=text.text.tostring();

然後將值傳送到bll業務邏輯層 經過業務邏輯的判斷後傳到dal資料訪問層 插入資料庫

至於sql語句 update 表 set 列=? where 條件 例如id=1;

將xx表的xx列改為? 條件是id必須為1的

希望我的回答對您有幫助!

9樓:匿名使用者

using system.data.sqlclient;

string ***=texbox1.text.tostring().trim();

string str = "data source=資料庫機器名;initial catalog=資料庫名;integrated security=true";

sqlconnection con = new sqlconnection(str);

con.open();

cmd=new sql***mand("要是插入資料就用insert into 改變資料就用 update ",con);

cmd.executenonquery();

sql資料庫的插入和更改的方法你應該會的吧 嘻嘻

10樓:匿名使用者

1.假設文字框為textbox1,在後臺可用這句獲取其值string str = this.textbox1.text;

2.然後執行sql新增操作(其中conn為資料庫連線,table為表名,name為欄位名):

sql***mand cmd = new sql***mand("insert into table(name) values(str)",conn);

conn.executenonquery();

11樓:匿名使用者

private static string connectionstrings = configurationmanager.connectionstrings["sqlstr"].connectionstring;

寫一個 string sql="insert into table values('"+textbox1.text+"')";

呼叫下面方法,如果

返回 1 證明已經新增進去

public static int execute***mand(string safesql)

catch (exception e)

finally

}private static void prepare***mand(sql***mand cmd, sqlconnection connection, sqltransaction trans, ***mandtype cmdtype, string cmdtext, sqlparameter cmdparms)

else if (connection.state == system.data.connectionstate.closed)

else if (connection.state == system.data.connectionstate.broken)

cmd.connection = connection;

cmd.***mandtext = cmdtext;

cmd.***mandtimeout = 50;

if (trans != null)

if (cmdtype != null)

if (cmdparms != null)}

visual studio用c#程式設計如何向sql表中插入textbox中輸入的資料?

12樓:志華

//資料庫連線字串

sqlconnection conn=new sqlconnection("server=.;database=db;uid=sa;pwd=123");

conn.open()

string sql="insert into tabel(***,***,***)value (***,***,' "+textbox.text+" ')";

sql***mand ***m=new sql***mand(conn,sql);

***m.executenonquery(); //執行sql語句。向資料庫中插入資料

13樓:匿名使用者

要用 c# 執行你的 insert into 語句。

14樓:匿名使用者

看一下ado.***

如何用C 將字串倒序排列,如何用C 將一個字串倒序排列

有漢字的話,要加一個if語句來判斷,然後i要自加2,因為漢字佔兩個位元組 include using namespace std int main b 0 cout buf return 0 兩個問題 i換成i 因為前者是先計算再引用,後面是先引用再計算b 將b指標向後移動,迴圈結束後b已經到了字串...

如何用c 寫簡單的計算器程式,如何用c 寫一個簡單的計算器程式

include include include using namespace std void main cout number2 cin rightparstr leftparint atoi leftparstr.c str rightparint atoi rightparstr.c str...

如何用c寫編譯器,如何用c寫一個編譯器

先學編譯原理。然後根據步驟,1 處理預編譯 2 詞法分析 3 語法分析 4 語義分析 5 中間 轉換 6 二進位制 生成。簡單起見,不需要考慮優化。初期可以不需要支援太多語法。怎樣去寫一個編譯器 用c語言寫c語言編譯器 需 這個需要考慮到很多的問題 各種錯誤的型別 以及可能出現的情況 這個可以先去看...