Vb.net 4文本框1 datagridview 1保存按钮sqldatabase中的惰性值如何 [英] Vb.net 4 textbox 1 datagridview 1 save button how inert value in sqldatabase

查看:132
本文介绍了Vb.net 4文本框1 datagridview 1保存按钮sqldatabase中的惰性值如何的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试vb.net销售模块,模块4文本框值添加1个datagridview 4列值,另外4个文本框值插入sql数据库单个数据表8列值。但是值不插入如何解决problam



我尝试过:



i am trying vb.net sales module that module 4 textbox value add in 1 datagridview 4 column value , another 4 textbox value insert in sql database single data table 8 column value.but value not insert how to solve the problam

What I have tried:

con.Open()
com.CommandText = "insert into three(sid,supid,supname,supperson) values((@sid,@supid,@supname,@supperson)"
com.Parameters.AddWithValue("@sid", TextBox1.Text)
com.Parameters.AddWithValue("@supid", TextBox2.Text)
com.Parameters.AddWithValue("@supname", TextBox3.Text)
com.Parameters.AddWithValue("@supperson", TextBox4.Text)
For i As Integer = 0 To DataGridView1.Rows.Count - 1
com.CommandText = "insert into three(pno,pname,qty,price) values((@pno,@pname,@qty,@price)"
com.Parameters.AddWithValue("@pno", DataGridView1.Rows(i).Cells(0).Value)
com.Parameters.AddWithValue("@pname", DataGridView1.Rows(i).Cells(1).Value)
com.Parameters.AddWithValue("@qty", DataGridView1.Rows(i).Cells(2).Value)
com.Parameters.AddWithValue("@price", DataGridView1.Rows(i).Cells(3).Value)
com.ExecuteNonQuery()
Next
connection.Close(

推荐答案

我回答了前面这里完全相同的问题: Vb.net 4 textbox 1 datagridview 1保存按钮sqldatabase中的惰性值 [ ^ ]。



根据帖子你还没有尝试过建议的操作。所以尝试使用以下内容。我手边没有编译器,对于任何错别字都很抱歉



I answered the exact same question earlier here: Vb.net 4 textbox 1 datagridview 1 save button how inert value in sqldatabase[^] .

Based on the post you have not tried the suggested actions. So have a try with something like the following. I don't have a compiler at hand so sorry for any typos

con.Open()
com.CommandText = "insert into three(sid,supid,supname,supperson) values(@sid,@supid,@supname,@supperson)"
com.Parameters.AddWithValue("@sid", TextBox1.Text)
com.Parameters.AddWithValue("@supid", TextBox2.Text)
com.Parameters.AddWithValue("@supname", TextBox3.Text)
com.Parameters.AddWithValue("@supperson", TextBox4.Text)
com.ExecuteNonQuery()

com.CommandText = "insert into three (pno,pname,qty,price) values (@pno,@pname,@qty,@price)"
com.Parameters.Add("@pno", SqlDbType.VarChar, 100)
com.Parameters.Add("@pname", SqlDbType.VarChar, 100)
com.Parameters.Add("@qty", SqlDbType.VarChar, 100)
com.Parameters.Add("@price", SqlDbType.VarChar, 100)
For i As Integer = 0 To DataGridView1.Rows.Count - 1
   com.Parameters("@pno").Value = DataGridView1.Rows(i).Cells(0).Value
   com.Parameters("@pname".Value = DataGridView1.Rows(i).Cells(1).Value
   com.Parameters("@qty".Value = DataGridView1.Rows(i).Cells(2).Value
   com.Parameters("@price".Value = DataGridView1.Rows(i).Cells(3).Value
   com.ExecuteNonQuery()
Next
connection.Close(





前一个答案中的所有问题仍然适用,并在使用此代码之前检查数据类型和长度。例如,我不知道PNO的类型是varchar还是其他。



All the questions in the previous answer still apply and check the data type and lengths prior using this code. For example I do not know if the type of PNO is varchar or something else.


这篇关于Vb.net 4文本框1 datagridview 1保存按钮sqldatabase中的惰性值如何的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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