在文本框中输入的数据应保存在数据库中 [英] entered data in textbox should save in database
本文介绍了在文本框中输入的数据应保存在数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有3个文本框我需要在sql表中保存输入的文本
i have 3 text boxes i need to save the entered text in my sql table
推荐答案
private void btnSaveData_Click(object sender,EventArgs e)
{
string sql =插入客户(customername,contactno,email)值('+ textBox1.Text +','+ textBox2.Text +',' + textBox3.Text +');
尝试
{
SqlConnection con = new SqlConnection();
con.ConnectionString =data source = rakesh-PC; Initial catalog = mysoftdb; user id = sa; password = ruhil;
con.Open();
SqlCommand objCmd = new SqlCommand(sql,con);
SqlDataAdapter objDA = new SqlDataAdapter(objCmd);
DataSet ds = new DataSet();
objDA.Fill(ds,dtEmployee);
MessageBox.Show(数据已保存);
}
catch(例外情况)
{
MessageBox.Show(错误是+ ex.Message);
}
}
这个代码用于在ms sql server中保存日期你可以替换其他数据库的小语法。
private void btnSaveData_Click(object sender, EventArgs e)
{
string sql="insert into customer(customername,contactno,email)values('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "')";
try
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "data source=rakesh-PC; Initial catalog=mysoftdb; user id=sa;password=ruhil";
con.Open();
SqlCommand objCmd = new SqlCommand(sql, con);
SqlDataAdapter objDA = new SqlDataAdapter(objCmd);
DataSet ds = new DataSet();
objDA.Fill(ds, "dtEmployee");
MessageBox.Show("Data has been saved");
}
catch (Exception ex)
{
MessageBox.Show("error is " + ex.Message);
}
}
This code is used to save date in ms sql server u can replace little syntax for other databases.
这篇关于在文本框中输入的数据应保存在数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文