c中,如何把TextBox中的值寫入sql2019資料庫

2021-04-01 08:14:29 字數 5283 閱讀 2770

1樓:匿名使用者

insert into ck(材料編號,材料名稱

) values("+textbox1.text+"'','"+textbox2.text+"')

在web.config檔案中新增資料庫連線字串:

2樓:匿名使用者

你得好好學習學習ado.***了,這是基礎 。基本功都沒練好就要闖江湖,好高騖遠

3樓:沉香ai小玉

取到值用sql語句插入。1

4樓:匿名使用者

string a1,a2,con;

a1=textbox1.text();

a2=textbox2.text();

insert into ck (材料編

號,材料名稱) values(a1,a2);

con="data source=localhost; initial catalog=vms;user id=sa;pwd=sa!"

sqlconnection connection =new sqlconnection(con);

connection.connectionstring=con;

connection.open();

5樓:匿名使用者

你直接拿textbox的tex就行了

如何用c#將textbox資料寫入sql server資料表

6樓:何苦庸人自擾呢

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

7樓:匿名使用者

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

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

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

return;

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

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

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

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

8樓:匿名使用者

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

9樓:匿名使用者

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

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

10樓:匿名使用者

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

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

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

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

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

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

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

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

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

11樓:匿名使用者

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資料庫的插入和更改的方法你應該會的吧 嘻嘻

12樓:匿名使用者

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();

13樓:匿名使用者

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)}

c#怎樣textbox中的內容寫入到資料庫中

14樓:匿名使用者

1、先把textbox.text.tostring()寫到你定義的變數。

string txtstr = textbox.text;

2、建立連線

sqlconnection con = new sqlconnection("server=.;database=hostel;uid=你資料庫管理員名;pwd=密碼專";

3、開啟數屬據庫

con.open()

4、對資料庫進行操作(這幾步基本上的書都應該有吧)

sql***mand cmd = new sql***mand(insert into manage values(txtstr),con);

cmd.excutenonquery();

cmd.***mandtype = ***mandtype.text;

con.close();

夠清楚了吧 手寫的可能會有些毛病 但大概意思就是這樣

希望對你有幫助

15樓:匿名使用者

sqlconnection con=new sqlconnection("server=.;database=hostel;baitrusted_connection=true");

con.open();

sql***mand cmd = new sql***mand(insert into manage values(@

duhostelid),con);

cmd.paramer.addwithvalue("@hostelid",textbox1.text);

cmd.excutenonquery();

con.close();

裡面大zhi

小寫有dao錯誤回!答!

16樓:匿名使用者

連線資料庫 具體什麼樣的資料庫具體連線

插入欄位 insert into manege (hostelid)values( 'textbox的內容' )

17樓:匿名使用者

那就寫一個sql語句 連線資料庫 然後執行sql語句 insert into manage values('你的文字框內容')

18樓:匿名使用者

就是個基本的sql寫入語句,

19樓:匿名使用者

現在最好用ado.***建立資料庫連線

怎樣在c#在textbox中輸入資料自動存入資料庫

20樓:楷銥浴鍶

1、先把textbox.text.tostring()寫到你定義的變數。

string txtstr = textbox.text;

2、建立連線

sqlconnection con = new sqlconnection("server=.;database=hostel;uid=你資料庫管理員名;pwd=密碼";

3、開啟資料庫

con.open()

4、對資料庫進行操作(這幾步基本上的書都應該有吧)

sql***mand cmd = new sql***mand(insert into manage values(txtstr),con);

cmd.excutenonquery();

cmd.***mandtype = ***mandtype.text;

con.close();

夠清楚了吧 手寫的可能會有些毛病 但大概意思就是這樣

asp.*** c#語言 將textbox中寫入的資訊如何存入sql資料庫,並且對資料庫的資訊進行更新?謝謝了。

21樓:切啫

定義好sql字元就可以了啊,例如

string mysqlcmd="update database set myvalue='"+textbox.text+"' where id='xx'";

然後執行這個查詢就可以了

C中textBox1 Text的數值如何在textBox

選擇 工具 載入bai巨集,選取 分析工具du庫 zhi,確定。然後在 dao函式 中選擇回 工程 分類,就可以看到答各種進位制轉換函式了。選這個函式hex2dec number 括號中number為你要轉換成10進位制的十六進位制數!或者用wps更方便 c 如何將任意16進位制字串顯示到textb...

C動態新增控制元件textbox,求教 C 窗體中動態新增了Panel,再如何動態的在Panel中新增文字框控制元件呢?

textbox txt new textbox string s private void button1 click object sender,eventargs e private void form1 load object sender,eventargs e 這話問的 你希望 s 是什麼...

c中在textbox1和textbook2輸入的文字值輸入自動計算顯示在textbox3中

在第二個文字框的textboxchanged裡寫 內部維護一個list,計算兩個站的index的差 liststationlist new list int startindex 0 int endindex 0 private void textbox1 textchanged object se...