如何在c#.net windows应用程序中一次更新或插入多行datagridview? [英] How to update or insert multiple row of datagridview at a time in c# .net windows application?

查看:60
本文介绍了如何在c#.net windows应用程序中一次更新或插入多行datagridview?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,



如何在c#.net windows应用程序中一次插入和更新多行datagridview?

i有一个使用c#.net windows应用程序通过数据gridview插入和更新数据到表中的代码。



Hello,

How to insert and update multiple row of datagridview at a time in c# .net windows application?
i have a code for insert and update data in to the table through data gridview using c# .net windows application.

SqlConnection con = new SqlConnection(cnString1);
if (con.State == ConnectionState.Closed)//check whether connection to database is close or not
    con.Open();//if connection is close then only open the connection
SqlCommand cmd = new SqlCommand("MergeInsertUpdateKreeationMainUnit", con);//create a SQL command object by passing name of the stored procedure and database connection 
cmd.CommandType = CommandType.StoredProcedure; //set command object command type to stored procedure type
cmd.Parameters.Add("@KreationName ", SqlDbType.VarChar).Value = dataGridView1.CurrentRow.Cells["KreationName"].Value;
cmd.Parameters.Add("@KreationID", SqlDbType.Int).Value = dataGridView1.CurrentRow.Cells["KreationID"].Value;
cmd.Parameters.Add("@KreationThumbnailLocation", SqlDbType.VarChar).Value = dataGridView1.CurrentRow.Cells["KreationThumbnailLocation"].Value;
cmd.Parameters.Add("@KreationNmoPath", SqlDbType.VarChar).Value = dataGridView1.CurrentRow.Cells["KreationNmoPath"].Value;
cmd.Parameters.Add("@KreationType", SqlDbType.VarChar).Value = dataGridView1.CurrentRow.Cells["KreationType"].Value;
cmd.Parameters.Add("@KreationUID", SqlDbType.VarChar).Value = dataGridView1.CurrentRow.Cells["KreationUID"].Value;
cmd.Parameters.Add("@KreationHangingRod", SqlDbType.VarChar).Value = dataGridView1.CurrentRow.Cells["KreationHangingRod"].Value;
cmd.Parameters.Add("@KreationLocker", SqlDbType.VarChar).Value = dataGridView1.CurrentRow.Cells["KreationLocker"].Value;
cmd.Parameters.Add("@KreationDrawer", SqlDbType.VarChar).Value = dataGridView1.CurrentRow.Cells["KreationDrawer"].Value;
cmd.Parameters.Add("@KreationShelf", SqlDbType.VarChar).Value = dataGridView1.CurrentRow.Cells["KreationShelf"].Value;
cmd.ExecuteNonQuery();//execute command 
MessageBox.Show(" Updated Successfully!!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);





但是我有一个问题,我们无法插入和更新多行数据,或者我们只能插入和更新当前行的数据。



请给我一个多行解决方案插入和更新或者它不可能如此,我们如何根据一行插入进行验证。



请帮助我。这很紧急。



先谢谢。



Ankit Agarwal

软件工程师



but i have a problem, we can not insert and update multiple rows of data or we can insert and update data only current row.

Please give me a solution for multiple rows insert and update or it cant't possible so, how can we get validation according to one row insert.

Please help me. It's urgent.

Thanks in Advance.

Ankit Agarwal
Software Engineer

推荐答案

如果您使用的是SQL Server 2008或2010,则可以选择传递数据表

作为参数,ii pass通过一种称为表类型的技术,您也可以将参数作为XML发送并使用游标循环XML。
If you are using SQL Server 2008 or 2010, there is a option for passing Data Table
as a parameter,ii pass through a technique called "table Type", also you can send parameter as XML & can loop the XML using cursor.


看看 - 如何使用Visual C#.NET中的SqlDataAdapter对象更新SQL Server数据库 [ ^ ]。


这篇关于如何在c#.net windows应用程序中一次更新或插入多行datagridview?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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