在datagridview中显示出来的数据行列中,随意选中一行,然后点击界面上的提交按键,实现把该记录提交到数据库的另外一张表,这个功能试了很多次都没有实现,有没有高手啊,跪求代码啦!!!!!!!!!!!!!!

解决方案 »

  1.   

    你直接insert into 那张表好了
      

  2.   

    直接的试过的啦,你要查询出来的数据显示在datagridview中,然后又要实现点击其中的任意一条记录,才可以实现把该选中的记录提交到另外一张表中。问题是我没有那个代码啊,有些地方没有了解。
      

  3.   

    多了解下datagridview吧,不要什么都是代码,代码能解决一时解决不了一世的哈
      

  4.   

    点击datagridview里面的数据的时候 根据主键查询出这数据的详细信息 然后再把需要添加的数据截取出来添加到另外一张表啊。。
    不知道LZ为什么说不行啊 。。 是不是你另外表的一些约束没弄好啊 ?
      

  5.   

    你所说的随意选中一行是怎么个选法,用checkbox控件吗,如果是的话就很容易啊
      

  6.   

    datagridview1..CurrentRow.Cells["Field"].Value取每列的值,然后执行insert into就可以了
      

  7.   

    这个就可以实现
    ADO.NET不会?
    SqlClient
    SqlConnection
    SqlCommand(Text属性是关键)
    Open
    ExecuteNonQuery
      

  8.   

    楼上的都是正解吖~把dgv的数据提出来insert就行啦
      

  9.   


     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);