本文介绍了来自datagridview的SQL INSERT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我正在尝试插入sql server。但是除了datagridview列(1)中的值之外,所有数据都会被插入。请通知错误的地方。请帮我。列(1)中的值总是像发票金额一样的数值。 Button1点击事件 ******** ************************************************** ******** Dim conn 正如 字符串 =( 数据源= BASHEER-PC;初始目录=同志;用户ID = sa;密码= QDCqdc123) Dim Cn 作为 新 SqlConnection(conn) Dim mycommand As 新 SqlCommand mycommand.CommandType = CommandType.StoredProcedure mycommand.CommandText = Invapp Dim i As 整数 Convert.ToInt32(DataGridView3.Rows(i).Cells( 1 )。Value) 对于 i = 0 DataGridView3.RowCount - 1 mycommand.Parameters.Add( @ Voucher_Type, SqlDbType.NChar).Value = RV mycommand.Parameters.Add( @ voucher_no,SqlDbType.Int).Value = Txtrvno.Text mycommand.Parameters.Add ( @ Account_number,SqlDbType.VarChar).Value = Txtcraccountno.Text mycommand。参数.Add( @ Account_name,SqlDbType.VarChar).Value = Txtcraccountname.Text mycommand.Parameters.Add( @ Debit_Amount,SqlDbType.Money).Value = 0 mycommand.Parameters.Add( @ Credit_Amount,SqlDbType.Money).Value = 0 mycommand.Parameters.Add( @ Voucher_date,SqlDbType.SmallDateTime).Value = Txtdate.Text mycommand.Parameters.Add( @ Bal_Amount,SqlDbType.NVarChar).Value = DataGridView3.Rows(i).Cells( 1 )。价值 mycommand.Connection = Cn 尝试 Cn.Open() mycommand.ExecuteNonQuery() MsgBox( 成功发布,MsgBoxStyle.Information) Cn.Close() Catch ex As 异常 ' 抛出前 最后 Cn.Dispose() ' 结束捕获 结束 尝试 下一步 解决方案 I am trying to insert to sql server. But all datas are inserted except the values in the datagridview column(1). Please notify where I did mistake. Please help me. The values in columns(1) always a numerical value like invoice amount.Button1 click event******************************************************************Dim conn As String = ("Data Source=BASHEER-PC;Initial Catalog=comrade;User ID=sa;Password=QDCqdc123") Dim Cn As New SqlConnection(conn) Dim mycommand As New SqlCommand mycommand.CommandType = CommandType.StoredProcedure mycommand.CommandText = "Invapp" Dim i As Integer Convert.ToInt32(DataGridView3.Rows(i).Cells(1).Value) For i = 0 To DataGridView3.RowCount - 1 mycommand.Parameters.Add("@Voucher_Type", SqlDbType.NChar).Value = "RV" mycommand.Parameters.Add("@voucher_no", SqlDbType.Int).Value = Txtrvno.Text mycommand.Parameters.Add("@Account_number", SqlDbType.VarChar).Value = Txtcraccountno.Text mycommand.Parameters.Add("@Account_name", SqlDbType.VarChar).Value = Txtcraccountname.Text mycommand.Parameters.Add("@Debit_Amount", SqlDbType.Money).Value = 0 mycommand.Parameters.Add("@Credit_Amount", SqlDbType.Money).Value = 0 mycommand.Parameters.Add("@Voucher_date", SqlDbType.SmallDateTime).Value = Txtdate.Text mycommand.Parameters.Add("@Bal_Amount", SqlDbType.NVarChar).Value = DataGridView3.Rows(i).Cells(1).Value mycommand.Connection = Cn Try Cn.Open() mycommand.ExecuteNonQuery() MsgBox("Posted Sucessfully", MsgBoxStyle.Information) Cn.Close() Catch ex As Exception ' Throw ex Finally Cn.Dispose() ' end catch End Try Next 解决方案 这篇关于来自datagridview的SQL INSERT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-21 08:29