如何更新多个教科书值 [英] how can update multiple textbook values
本文介绍了如何更新多个教科书值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在从负载中检索该值,我想通过点击更新按钮更新
i am retrieving that value in from load i want to update by click the update button
SqlConnection cn;
SqlDataAdapter da;
cn = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ConnectionString);
da = new SqlDataAdapter("select * from home", cn);
DataSet ds = new DataSet();
da.Fill(ds);
TextBox1.Text = ds.Tables[0].Rows[0][1].ToString();
TextBox2.Text = ds.Tables[0].Rows[0][2].ToString();
TextBox3.Text = ds.Tables[0].Rows[1][1].ToString();
TextBox4.Text = ds.Tables[0].Rows[1][2].ToString();
TextBox5.Text = ds.Tables[0].Rows[2][1].ToString();
TextBox6.Text = ds.Tables[0].Rows[2][2].ToString();
TextBox7.Text = ds.Tables[0].Rows[3][1].ToString();
TextBox8.Text = ds.Tables[0].Rows[3][2].ToString();
推荐答案
编写更新查询以从文本框控件获取更新的文本
和将查询传递给下面提供的此方法。当命令成功执行查询时,该方法返回1,否则返回0.
string query =update tablename set col1 = textname1,..... where condition ;
Write the update query to get the updated text from the textbox control
and pass the query to this method provided below. The method returns 1 when the command executes query successfully else it returns 0.
string query = "update tablename set col1=textname1,..... where condition";
public int ExecuteCommand(string query)
{
int RowsAffected = 0;
cn = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ConnectionString);
SqlCommand Command = null;
try
{
Command = new SqlCommand(query, cn );
RowsAffected = Command.ExecuteNonQuery();
}
catch (Exception e)
{
throw new Exception(e.Message + "<br>" + query);
}
finally
{
Command.Dispose();
Command = null;
cn.Close();
cn.Dispose();
}
return RowsAffected;
}
</br>
hi ..
这是更新示例代码
hi..
this is the sample code for update
protected void Update_Click(object sender, EventArgs e)//TO UPDATE THE EDITED RECORD
{
SqlCommand cmd = new SqlCommand();
con.Open();
string strQuery = "UPDATE Country_master SET [CountryCode]='" + txt_countrycode.Text + "', [CountryName]='" + txt_countryname.Text + "',[IsActive]=" + active + " WHERE CountryId=" + txt_countryid.Text + " ";
cmd = new SqlCommand(strQuery, con);
cmd.ExecuteNonQuery();
}
希望这对你有所帮助
快乐编码:)
hope this helps you
Happy Coding :)
在按钮点击事件中发布您在问题中发布的代码。如
Post the code that you posted in you question in a button click event..like
protected void Update_Click(object sender, EventArgs e)
{
SqlConnection cn;
SqlDataAdapter da;
cn = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ConnectionString);
da = new SqlDataAdapter("select * from home", cn);
DataSet ds = new DataSet();
da.Fill(ds);
TextBox1.Text = ds.Tables[0].Rows[0][1].ToString();
TextBox2.Text = ds.Tables[0].Rows[0][2].ToString();
TextBox3.Text = ds.Tables[0].Rows[1][1].ToString();
TextBox4.Text = ds.Tables[0].Rows[1][2].ToString();
TextBox5.Text = ds.Tables[0].Rows[2][1].ToString();
TextBox6.Text = ds.Tables[0].Rows[2][2].ToString();
TextBox7.Text = ds.Tables[0].Rows[3][1].ToString();
TextBox8.Text = ds.Tables[0].Rows[3][2].ToString()
}
这篇关于如何更新多个教科书值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文