0

I was hoping someone could offer me some help please
I am new to using asp.net .I want to create a web form with two comboboxes ,one text box and a button .I have multiple tables in ms access database with same structure , col1 and col2 .
I want to insert text box value into column1 in the table selected from combobox1 and into column2 in table selected from combobox2
such as if i select table1 from combobox1 and table2 from combobox2 and click on the button, data should be inserted into both table1 and table2.

i would like to know is it possible to do it in asp.net? if so what steps would be involved in doing it ? also can i use/modify the code from winfrom application
Thanks in advance

Imports System.Data.OleDb

Partial Public Class Form1
    Inherits Form
    Public Sub New()
        InitializeComponent()
    End Sub
    Private conn As OleDbConnection
    Private sda As OleDbDataAdapter
    Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
        conn = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\dtb.accdb;Jet OLEDB:Database Password=****")
        sda = New OleDbDataAdapter([String].Empty, conn)
        conn.Open()

        ComboBox2.DataSource = conn.GetSchema("TABLES")
        ComboBox2.ValueMember = "TABLE_NAME"
        ComboBox2.DisplayMember = "TABLE_NAME"

        ComboBox1.DataSource = conn.GetSchema("TABLES")
        ComboBox1.ValueMember = "TABLE_NAME"
        ComboBox1.DisplayMember = "TABLE_NAME"
    End Sub

    Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)
        If ComboBox1.SelectedItem IsNot Nothing AndAlso ComboBox2.SelectedItem IsNot Nothing AndAlso TextBox1.Text IsNot Nothing Then
            Dim cmd As OleDbCommand = conn.CreateCommand()
            cmd.CommandText = ("insert into " + ComboBox1.Text & "(studName) values('") + TextBox1.Text & "')"
            sda.InsertCommand = cmd
            sda.InsertCommand.ExecuteNonQuery()
            cmd.CommandText = ("insert into " + ComboBox2.Text & "(studName) values('") + TextBox1.Text & "')"
            sda.InsertCommand = cmd
            sda.InsertCommand.ExecuteNonQuery()
            sda.Dispose()
            conn.Close()
            conn.Dispose()
        End If
    End Sub
End Class
2
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by david081
0

Write two insert commands for combobox1 and combobox2 (for both tables) on button click.... your line number 29 and 32 tells us that combobox contain your table names is it right?

Edited by abelLazm: n/a

0

Hi parmalink
Thank you for response. yes,studName is table name, i used same table name in both insert command .I dont know how to write the insert command that does not mention any table name because i want to insert into the selected table, not into the table mentioned into sql command.if there is anyway to get it to work , please help me ..

0

Hi - I got this from vb.net section of the same forum ,I paste it here incase someone need

cmd.CommandText = "INSERT INTO " & combobox.SelectedItem & " (<field>) VALUES ('" & textbox.Text & "')"cmd.CommandText = "INSERT INTO " & combobox.SelectedItem & " (<field>) VALUES ('" & textbox.Text & "')"
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.