如何更新多个教科书值

编程入门 行业动态 更新时间:2024-10-24 03:25:09
本文介绍了如何更新多个教科书值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在从负载中检索该值,我想通过点击更新按钮更新

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

更多推荐

如何更新多个教科书值

本文发布于:2023-10-26 11:58:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1530069.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   教科书

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!