怎么实现这个功能? 在datagridview中显示出来的数据行列中,随意选中一行,然后点击界面上的提交按键,实现把该记录提交到数据库的另外一张表,这个功能试了很多次都没有实现,有没有高手啊,跪求代码啦!!!!!!!!!!!!!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你直接insert into 那张表好了 直接的试过的啦,你要查询出来的数据显示在datagridview中,然后又要实现点击其中的任意一条记录,才可以实现把该选中的记录提交到另外一张表中。问题是我没有那个代码啊,有些地方没有了解。 多了解下datagridview吧,不要什么都是代码,代码能解决一时解决不了一世的哈 点击datagridview里面的数据的时候 根据主键查询出这数据的详细信息 然后再把需要添加的数据截取出来添加到另外一张表啊。。不知道LZ为什么说不行啊 。。 是不是你另外表的一些约束没弄好啊 ? 你所说的随意选中一行是怎么个选法,用checkbox控件吗,如果是的话就很容易啊 datagridview1..CurrentRow.Cells["Field"].Value取每列的值,然后执行insert into就可以了 这个就可以实现ADO.NET不会?SqlClientSqlConnectionSqlCommand(Text属性是关键)OpenExecuteNonQuery 楼上的都是正解吖~把dgv的数据提出来insert就行啦 public int AddGpsBarcode(int CustomerID, string BarcodeNO, int Type) { try { string sqlStr = "insert into Tab_CustomerBarcode(CB_ID,CB_CustomerID,CB_BarcodeNO,CB_Type,CB_State,CB_UpdateTime) values (@newGuid,@CustomerID,@BarcodeNO,@Type,0,@UpdateTime)"; sqlCommand = new SqlCommand(sqlStr, sqlConnection); sqlCommand.Parameters.Add(new SqlParameter("@newGuid", SqlDbType.UniqueIdentifier, 16)); sqlCommand.Parameters["@newGuid"].Value = Guid.NewGuid(); sqlCommand.Parameters.Add(new SqlParameter("@CustomerID", SqlDbType.Int, 4)); sqlCommand.Parameters["@CustomerID"].Value = CustomerID; sqlCommand.Parameters.Add(new SqlParameter("@BarcodeNO", SqlDbType.VarChar, 50)); sqlCommand.Parameters["@BarcodeNO"].Value = BarcodeNO; sqlCommand.Parameters.Add(new SqlParameter("@Type", SqlDbType.Int, 4)); sqlCommand.Parameters["@Type"].Value = Type; sqlCommand.Parameters.Add(new SqlParameter("@UpdateTime", SqlDbType.DateTime, 8)); sqlCommand.Parameters["@UpdateTime"].Value = DateTime.Now; return sqlCommand.ExecuteNonQuery(); } catch (Exception ex) { throw ex; } finally { if (sqlCommand != null) { sqlCommand.Dispose(); } sqlConnection.Close(); } }int ziduan1=datagridview1..CurrentRow.Cells["列名"].Valuestring ziduan2=datagridview1..CurrentRow.Cells["列名"].Valueint ziduan3=datagridview1..CurrentRow.Cells["列名"].Value用这个方法的时候,AddGpsBarcode(ziduan1,ziduan2,ziduan3); 求...Enumerable.Join方法讲解 超级平凡简单的问题 c# 文件拷贝求助(急) 大家给看一下,这段关于图片保存的代码 想对datalist的数据进行编辑,知道大约要用得edititemtemplate 通用API???? 请大家帮忙,写好的 web services 入何发布到远程服务器上运行 visual studio 2005中如何自动输入方法后面的一对括号 请问? .NET MVC 开发采用 http接口 关于SqlParameter的这段代码真的不知道错在哪儿了。。。 请问,Enumerable.Intersect取交集,为什么不成功?
不知道LZ为什么说不行啊 。。 是不是你另外表的一些约束没弄好啊 ?
ADO.NET不会?
SqlClient
SqlConnection
SqlCommand(Text属性是关键)
Open
ExecuteNonQuery
public int AddGpsBarcode(int CustomerID, string BarcodeNO, int Type)
{
try
{
string sqlStr = "insert into Tab_CustomerBarcode(CB_ID,CB_CustomerID,CB_BarcodeNO,CB_Type,CB_State,CB_UpdateTime) values (@newGuid,@CustomerID,@BarcodeNO,@Type,0,@UpdateTime)"; sqlCommand = new SqlCommand(sqlStr, sqlConnection); sqlCommand.Parameters.Add(new SqlParameter("@newGuid", SqlDbType.UniqueIdentifier, 16));
sqlCommand.Parameters["@newGuid"].Value = Guid.NewGuid(); sqlCommand.Parameters.Add(new SqlParameter("@CustomerID", SqlDbType.Int, 4));
sqlCommand.Parameters["@CustomerID"].Value = CustomerID; sqlCommand.Parameters.Add(new SqlParameter("@BarcodeNO", SqlDbType.VarChar, 50));
sqlCommand.Parameters["@BarcodeNO"].Value = BarcodeNO;
sqlCommand.Parameters.Add(new SqlParameter("@Type", SqlDbType.Int, 4));
sqlCommand.Parameters["@Type"].Value = Type;
sqlCommand.Parameters.Add(new SqlParameter("@UpdateTime", SqlDbType.DateTime, 8));
sqlCommand.Parameters["@UpdateTime"].Value = DateTime.Now; return sqlCommand.ExecuteNonQuery();
}
catch (Exception ex)
{
throw ex;
}
finally
{
if (sqlCommand != null)
{
sqlCommand.Dispose();
}
sqlConnection.Close();
}
}
int ziduan1=datagridview1..CurrentRow.Cells["列名"].Value
string ziduan2=datagridview1..CurrentRow.Cells["列名"].Value
int ziduan3=datagridview1..CurrentRow.Cells["列名"].Value
用这个方法的时候,AddGpsBarcode(ziduan1,ziduan2,ziduan3);