将动态文本框值从Gridview更新到数据库. [英] Update Dynamic textbox values from Gridview to database.

查看:66
本文介绍了将动态文本框值从Gridview更新到数据库.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

实际上,我已经将Gridview的动态文本框值更新为数据库,但是根据''rowindex''这是正确的.

但是现在我想根据GridView中的"ID"更新值. ''ID''正在从数据库中获取.

因此,我的代码中有一个小问题.

我应该在''ID''的代码中写些什么.

我已经使用此查询是正确的.但是我要使用''ID''代替''rowindex''.更新查询和部分代码在下面给出-

Actually I have Updated Dynamic Textbox values from Gridview to database but according to ''rowindex'' which is correct.

But Now I want to Update the values according to ''ID'' which is in GridView. ''ID'' is fetching from the database.

So There is a little problem in my code.

What should I write in my code for the ''ID''.

I have used this query which is correct. But in place of ''rowindex'', I want to use ''ID''. The update query and some part of the code is given below -

int count = GridView2.Rows.Count;
            for (int i = 0; i < count; i++)
            {
                TextBox box3 = (TextBox)GridView2.Rows[rowIndex].Cells[3].FindControl("TextBox3");
                TextBox box4 = (TextBox)GridView2.Rows[rowIndex].Cells[4].FindControl("TextBox4");
                sc.Add(box3.Text + "," + box4.Text);
                rowIndex++;
                conn.Open();
                string sqlStatement = "update SampleTable set Intime2='" + box3.Text + "',Outtime2='" + box4.Text + "' where ID='" + rowIndex + "'";
               
                SqlCommand cmd = new SqlCommand(sqlStatement, conn);
                cmd.CommandType = CommandType.Text;
                cmd.ExecuteNonQuery();
                conn.Close();
            }

推荐答案







for (int i = 0; i < count; i++)
{
TextBox box3 = (TextBox)GridView2.Rows[i].Cells[3].FindControl("TextBox3");
TextBox box4 = (TextBox)GridView2.Rows[i].Cells[4].FindControl("TextBox4");
sc.Add(box3.Text + "," + box4.Text);
rowIndex++;
conn.Open();
string sqlStatement = "update SampleTable set Intime2=''" + box3.Text + "'',Outtime2=''" + box4.Text + "'' where ID=''" + i+ "''";
SqlCommand cmd = new SqlCommand(sqlStatement, conn);
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
conn.Close();
} .



否则将ID绑定到标签并将其获取并将其传递给您的查询

希望这对您有帮助



or else bind the id to a label and fetch that and pass it to your query

Hope this helps


使用以下链接中所述的文章:

Gridview使用数据库中的动态数据插入,更新,编辑和删除 [
Use the article been stated down on the following link:

Gridview Insert, Update, Edit and Delete with dynamic data from database[^]


简单的解决方案是将ID绑定到gridview,然后轻松更新垂直行.

该id通过sql传递.
在特定的选定行上,您获取ID,然后使用它.
easy solution is u bind the id to gridview then u easily updated the perticular row.

that id passed throgh sql .
on perticular selected row u get id then used it.


这篇关于将动态文本框值从Gridview更新到数据库.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆