如何将多文本框数据插入访问多行 [英] how to insert multitextbox data into access multi row

查看:70
本文介绍了如何将多文本框数据插入访问多行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

租赁请帮我创建这个项目我是vb.net的新用户

请给我这个项目的源代码

vb.net并访问我有一个form - (名称,地址,年龄,联系号)12行3个文本框,(每行4个txtbox)4x3,将由用户填写并按提交按钮,所有4个记录将插入到数据库中。可能吗?请帮我说明怎么做。

谢谢

lease please help me to create this project i am new in vb.net
please give me source code for this project
vb.net and access i have a form - (Name,Address, Age ,Contact no) 12 textbox in 3 rows, (4 txtbox in each row) 4x3, which will be filled by the user and press the Submit button and all the 4 records will be inserted into Database. Is it possible? please assist me that how to do this.
thanks

推荐答案

两种解决方案满足您的要求。

1 )使用控制数组,这将最大限度地减少你对表格和编码部分的控制。



如果你的新的vb.net然后第二个解决方案对你更好。



Two solutions for your requirement.
1) use control array which will minimized your control on form and coding part.

if your new in vb.net then second solution will be better for you.

Dim cmd As New OleDbCommand
    Dim con As New OleDbConnection
        con.ConnectionString = "Provider=Microsoft.ace.oledb.12.0;Data Source=" & [your database path] & "; jet oledb:database password=[your password]"
        con.Open()

            cmd.CommandText = "INSERT INTO [your table name] ([Name],[Address],[Age],[ContactNo]) VALUES(@Name,@Address,@Age,@ContactNo)"
            cmd.Parameters.Clear()
            cmd.Parameters.Add("@Name", OleDbType.WChar).Value = txtname1.Text
            cmd.Parameters.Add("@Address", OleDbType.wchar).Value = txtaddress1.Text
            cmd.Parameters.Add("@Age", OleDbType.integer).Value = txtage1.Text
            cmd.Parameters.Add("@ContactNo", OleDbType.WChar).Value = txtcontactno1.Text
            cmd.Connection = con
            cmd.ExecuteNonQuery()

            cmd.Parameters.Clear()
            cmd.Parameters.Add("@Name", OleDbType.WChar).Value = txtname2.Text
            cmd.Parameters.Add("@Address", OleDbType.wchar).Value = txtaddress2.Text
            cmd.Parameters.Add("@Age", OleDbType.integer).Value = txtage2.Text
            cmd.Parameters.Add("@ContactNo", OleDbType.WChar).Value = txtcontactno2.Text
            cmd.Connection = con
            cmd.ExecuteNonQuery()

            cmd.Parameters.Clear()
            cmd.Parameters.Add("@Name", OleDbType.WChar).Value = txtname3.Text
            cmd.Parameters.Add("@Address", OleDbType.wchar).Value = txtaddress3.Text
            cmd.Parameters.Add("@Age", OleDbType.integer).Value = txtage3.Text
            cmd.Parameters.Add("@ContactNo", OleDbType.WChar).Value = txtcontactno3.Text
            cmd.Connection = con
            cmd.ExecuteNonQuery()

            cmd.Parameters.Clear()
            cmd.Parameters.Add("@Name", OleDbType.WChar).Value = txtname4.Text
            cmd.Parameters.Add("@Address", OleDbType.wchar).Value = txtaddress4.Text
            cmd.Parameters.Add("@Age", OleDbType.integer).Value = txtage4.Text
            cmd.Parameters.Add("@ContactNo", OleDbType.WChar).Value = txtcontactno4.Text
            cmd.Connection = con
            cmd.ExecuteNonQuery()





在列名周围使用括号。

因为你没有提到我在列名和texbox名称上面使用的列和文本框名称。



use brackets around column names.
as you have not mentioned columns and textboxes names I use above column name and texbox names.


这篇关于如何将多文本框数据插入访问多行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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