如何将“相同标签"下的文本框分配给数据库?(VB 2010) [英] How to assign the text boxes under Same Label to Data Base?(VB 2010)

查看:99
本文介绍了如何将“相同标签"下的文本框分配给数据库?(VB 2010)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以Windows应用程序形式为餐厅创建了一个数据库

所以我创建了列Item_No,Item_Name,Quantity,Price,Total,Grand Total

我将那个数据库拖放到了详细信息视图中.我以行格式排列

当我将数据插入文本框时,它适用于第一行文本框,并且还保存在名为Items的数据库中.

但是我想要在相同标签下放置4行文本框.所以我创建了

通过选择第一行文本框并按住Ctrl键,将多个文本框设为4

行.但是当我调试并输入文本但从第二行到第五行

输入的数据未分配给DB如何将数据分配给DB并存储.

我只创建了一个名为Items的数据库.

为了清楚地理解,请参见此图像,并帮助我为同一标签下的一行文本框创建数据库的必要详细信息

链接: http://www.mediafire.com/view/?e0nn3iv9a4jz7uv [

i created a database for restaurant in windows application form

so i created columns Item_No, Item_Name, Quantity, Price , Total, Grand Total

i dragged and dropped that that database as details view. i arranged in row format

below that their respective text boxes.When i insert the data into text boxes it works for the first row text boxes and also saving in my DB called Items.

But i want 4 rows of text boxes under those same labels.so i created

multiple text boxes by selecting first row text boxes and by holding Ctrl key i made 4

rows . but when i debugged and entered the text but from second row to fifth row

entered data was not assigning to DB how to assign that data to DB and to store it.

I created only single database named Items.

For clearly understanding see this image and help me necessary details for creating DB for row of text boxes under same label

Link: http://www.mediafire.com/view/?e0nn3iv9a4jz7uv[^]

推荐答案

它"除了Textbox之外,浏览网格的更好方法是不再创建Visual Studio .Net ...来创建Textbox数组...

在您的数据库中,将列名设置为"Sl.No","Item Name","Rate","Qty","Price".

在WindowsForm中正式添加为Form
的DataGridView控件

在代码表中尝试以下操作...

It''s a Better way to go through Grids other than Textbox Creating Array of Textboxes is no more Supported by Visual Studio .Net...

Let your Column Names be "Sl.No", "Item Name", "Rate", "Qty", "Price" in your DB.

Add an DataGridView Control in WindowsForm Formally Called as Form

In Code Sheet try as follows...

Imports System.Data.SQLClient

Dim Cn as SQLConnection
Dim Cmd as SqlCommand
Dim Rs as SqlDataReader

Private Sub SaveRecords()
Cn.Open("Enter_Your_Connection_String")
For i = 0 To Me.DataGridView1.Rows.Count - 1
    Cmd = Cn.CreateCommand()
    Cmd.CommandText = "INSERT INTO [Items] VALUES('"
    Cmd.CommandText = Cmd.CommandText & DataGridView1.Rows(i).Cells(0).Value & "','"
    Cmd.CommandText = Cmd.CommandText & DataGridView1.Rows(i).Cells(1).Value & "','"
    Cmd.CommandText = Cmd.CommandText & DataGridView1.Rows(i).Cells(2).Value & "','"
    Cmd.CommandText = Cmd.CommandText & DataGridView1.Rows(i).Cells(3).Value & "','"
    Cmd.CommandText = Cmd.CommandText & DataGridView1.Rows(i).Cells(4).Value & "','"
    Cmd.ExecuteNonQuery()
Next
Cn.Close
End Sub

Private Sub LoadRecords(ByVal Sender as Object, e as EventArgs) 'Handles MyBase.Load
Cn.Open("Enter_Your_Connection_String")
Cmd = Cn.CreateCommand()
Cmd.CommandText = "SELECT * FROM [Main Data]" 
   ' Change [Main Data] to Your Table Name
Rs = Cmd.ExecuteReader()
DataGridView1.Rows.Clear()
DataGridView1.ColumnCount = 5
DataGridView1.Columns(0).HeaaderText = "Sl.No"
DataGridView1.Columns(1).HeaaderText = "Item Name"
DataGridView1.Columns(2).HeaaderText = "Rate"
DataGridView1.Columns(3).HeaaderText = "Qry"
DataGridView1.Columns(4).HeaaderText = "Price"
Do Until Rs.Read()
DataGridView1.Rows.Add(Rs.GetValue(0), Rs.GetValue(1), Rs.GetValue(2), _
                          Rs.GetValue(3), Rs.GetValue(4))
Loop
Rs.Close
Cn.Close
End Sub


这篇关于如何将“相同标签"下的文本框分配给数据库?(VB 2010)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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