如何使用unqiue值更新gridview行 [英] How to update gridview row with unqiue values

查看:79
本文介绍了如何使用unqiue值更新gridview行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在gridview记录如下



Selectdata ID Transactionid数量价格状态



复选框1 1245 2 50 New

复选框2 1245 1 25新

复选框3 4568 1 10新

复选框4 2345 1 25新

复选框5 4568 1 10新



从上面的gridview我正在更新我从gridview中选择前两行并在数据库中更新



String strConnString = ConfigurationManager.ConnectionStrings [ConnectionStrings] .ConnectionString;

SqlConnection con = new SqlConnection(strConnString);

con.Open();

foreach(grdRpt.Rows中的GridViewRow行)

{

CheckBox cb =(CheckBox)row.FindControl( chkselecdata);

if(cb.Ch ecked == true)

{

int key = Convert.ToInt32(grdRpt.DataKeys [row.RowIndex] .Value);

SqlCommand cmd = new SqlCommand(UPDATE [transact]。[transaction_item] SET Status ='Ready'where transactee_id =+ key.ToString(),con);

cmd.ExecuteNonQuery();

}

}

con.Close();



i更新gridview已选中在运行模式下使用c#



行数据库我在gridview中为id 1245选择第一行,但在数据库1245中为数据库中更新的两行选择。



在上面的更新查询中如何获取对于交易ID 1245唯一的ID





上面代码中的错误是什么。





数据库输出我得到如下



我D Transactionid数量价格状态



1 1245 2 50新

2 1245 1 25新



我尝试过:



在gridview记录中如下



选择数据ID重复数量价格状态



复选框1 1245 2 50新

复选框2 1245 1 25新

复选框3 4568 1 10新

复选框4 2345 1 25新

复选框5 4568 1 10新



从上面的gridview我正在更新我从gridview中选择前两行并在数据库中更新



String strConnString = ConfigurationManager.ConnectionStrings [ConnectionStrings ] .ConnectionString;

SqlConnection con = new SqlConnection(strConnString);

con.Open();

foreach(grdRpt.Rows中的GridViewRow行)

{

CheckBox cb =(CheckBox)row.FindControl(chkselecdata);

if (cb.Checked == true)

{

int key = Convert.ToInt32(grdRpt.DataKeys [row.RowIndex] .Value);

SqlCommand cmd = new SqlCommand(UPDATE [transact]。[transaction_item] SET Status ='Ready'where transactee_id =+ key.ToString(),con);

cmd.ExecuteNonQuery() ;

}

}

con.Close();



i am在运行模式下使用c#



更新gridview选择行到数据库我在gridview中为id 1245选择第一行但在数据库1245中更新了两行在数据库中。



在上面的更新查询中如何获取ID whic h对于交易ID 1245是唯一的





我的上述代码中的错误是什么。





数据库输出我得到如下



ID Transactionid数量价格状态



1 1245 2 50新

2 1245 1 25新

3 4568 1 10新

4 2345 1 25新

5 4568 1 10新

In gridview record as follows

Selectdata ID Transactionid Qty Price Status

checkbox 1 1245 2 50 New
checkbox 2 1245 1 25 New
checkbox 3 4568 1 10 New
checkbox 4 2345 1 25 New
checkbox 5 4568 1 10 New

From the above gridview i am updating i am selecting first two rows from the gridview and upate in the database

String strConnString = ConfigurationManager.ConnectionStrings["ConnectionStrings"].ConnectionString;
SqlConnection con = new SqlConnection(strConnString);
con.Open();
foreach (GridViewRow row in grdRpt.Rows)
{
CheckBox cb = (CheckBox)row.FindControl("chkselecdata");
if (cb.Checked == true)
{
int key = Convert.ToInt32(grdRpt.DataKeys[row.RowIndex].Value);
SqlCommand cmd = new SqlCommand("UPDATE [transact].[transaction_item] SET Status = 'Ready' Where transactee_id=" + key.ToString(), con);
cmd.ExecuteNonQuery();
}
}
con.Close();

i am updating gridview selected row to database using c#

in the run mode i am selecting first row in the gridview for the id 1245 but in the database 1245 for the two rows updated in the database.

in the above update query how to get ID which is unique for Transaction id 1245


what is the mistake in my above code.


in the database ouput i get as follows

ID Transactionid Qty Price Status

1 1245 2 50 New
2 1245 1 25 New

What I have tried:

In gridview record as follows

Selectdata ID Transactionid Qty Price Status

checkbox 1 1245 2 50 New
checkbox 2 1245 1 25 New
checkbox 3 4568 1 10 New
checkbox 4 2345 1 25 New
checkbox 5 4568 1 10 New

From the above gridview i am updating i am selecting first two rows from the gridview and upate in the database

String strConnString = ConfigurationManager.ConnectionStrings["ConnectionStrings"].ConnectionString;
SqlConnection con = new SqlConnection(strConnString);
con.Open();
foreach (GridViewRow row in grdRpt.Rows)
{
CheckBox cb = (CheckBox)row.FindControl("chkselecdata");
if (cb.Checked == true)
{
int key = Convert.ToInt32(grdRpt.DataKeys[row.RowIndex].Value);
SqlCommand cmd = new SqlCommand("UPDATE [transact].[transaction_item] SET Status = 'Ready' Where transactee_id=" + key.ToString(), con);
cmd.ExecuteNonQuery();
}
}
con.Close();

i am updating gridview selected row to database using c#

in the run mode i am selecting first row in the gridview for the id 1245 but in the database 1245 for the two rows updated in the database.

in the above update query how to get ID which is unique for Transaction id 1245


what is the mistake in my above code.


in the database ouput i get as follows

ID Transactionid Qty Price Status

1 1245 2 50 New
2 1245 1 25 New
3 4568 1 10 New
4 2345 1 25 New
5 4568 1 10 New

推荐答案

请不要为每一步打开新问题,我已经告诉过你该做什么,一个小谷歌很容易解决你的问题。

Please dont open new Questions for every step, i already told you what to do, a little google would have easily solved your problem.
You need to UPDATE [...] WHERE ID=[1,2,3,4,5,e.g.] 
NOT         UPDATE [...] WHERE transactee_id=[1245,4568,e.g.]



如果您在从GridView获取ID时出现问题,那么除了您自己之外没有其他人可以帮助,因为我们不知道您的数据来自何处或如何存储。

如果你的网格视图中显示了你的ID,你可以从那里获得它


If you are having Problems getting your ID from GridView then nobody except yourself can help, because we don't know where your data is from or how it is stored.
If you have your ID shown in your gridview you might be able to get it from there


这篇关于如何使用unqiue值更新gridview行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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