日期:2014-05-20  浏览次数:20820 次

请教Sql insert 数据问题。
如何做到在TextBox   中输入的数据插入到Sql中所指定的字段?----既Save后Update到Sql.

------解决方案--------------------
用SqlCommand对象很容易实现.....
自己去找帮助...
------解决方案--------------------
+ textbox1.text +
把SQL语句中的具体值用这个取代。
------解决方案--------------------
msdn 里面有范例了。



------解决方案--------------------
/// <summary>
/// 新建用户资料
/// </summary>
/// <param name= "sacc "> </param>
/// <param name= "spw "> </param>
/// <param name= "snanme "> </param>
/// <param name= "slv "> </param>
/// <returns> </returns>
public bool saveUser(string sacc, string spw, string snanme, string slv,string dTime)
{
string sql = " ";
sql = "insert into [Admin] " +

"(user_name,user_acc,user_pw,user_lv,user_date) " +
" values( ' " +
sacc + " ', ' " +
spw + " ', ' " +
snanme + " ', ' " +
slv + " ',# " +
dTime + "#) ";

try
{
this.ExecuteSql(sql);
}
catch (Exception e)
{
MessageBox.Show(e.Message, "错误 ", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}

return true;
}

/// <summary>
/// 执行SQL语句,返回影响的记录数
/// </summary>
/// <param name= "SQLString "> </param>
/// <returns> </returns>
public int ExecuteSql(string SQLString)
{
using (OleDbConnection connection = new OleDbConnection(connectionString))
{
using (OleDbCommand cmd = new OleDbCommand(SQLString, connection))
{
try
{
connection.Open();
int rows = cmd.ExecuteNonQuery();
return rows;
}
catch (System.Data.OleDb.OleDbException E)
{
throw new Exception(E.Message);
}
}
}
}

--------------->
调用:saveUser(TextBox1.text,TextBox2.text,TextBox3.text,TextBox4.text,TextBox5.text);