locked
Send Multiple data to database RRS feed

  • Question

  • User1939751242 posted

    Ok so I have a webform that works fine when attempting to send the data to an access database, see code below. The site has a few dropdowns and a few textboxes. When the user hits submit, it sends the data to a 2007 Access database. Now they want my end-users to be able to submit multiple entries from the form. They want the user to have the ability to send up to 5 entries per page. I know this will possibly require a loop somewhere but I am not very familiar with loop statements. Can someone help point me in the right direction or provide some coding assistance. As you can see I have not started with the multiple entries as I am not sure where to begin. I am new to looping, vb.net, web forms. Any and all help would be greatly appreciated.

        Dim strSQL As String = "INSERT INTO RetailTest " & "(CSRName, DateofEntry, ScheduleStart, ScheduleEnd, ProjectNumber, TaskCompleted, TaskStart, TaskEnd, TaskCount, TaskNotes) Values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
            Dim dbComm As New OleDbCommand(strSQL, objConnection)
    
            dbComm.Parameters.Add("CSRName", OleDbType.VarChar, 255, "CSRName")
            dbComm.Parameters.Add("DateofEntry", OleDbType.VarChar, 255, "DateofEntry")
            dbComm.Parameters.Add("ScheduleStart", OleDbType.VarChar, 255, "ScheduleStart")
            dbComm.Parameters.Add("ScheduleEnd", OleDbType.VarChar, 255, "ScheduleEnd")
            dbComm.Parameters.Add("ProjectNumber", OleDbType.VarChar, 255, "ProjectNumber")
            dbComm.Parameters.Add("TaskCompleted", OleDbType.VarChar, 255, "TaskCompleted")
            dbComm.Parameters.Add("TaskStart", OleDbType.VarChar, 255, "TaskStart")
            dbComm.Parameters.Add("TaskEnd", OleDbType.VarChar, 255, "TaskEnd")
            dbComm.Parameters.Add("TaskCount", OleDbType.VarChar, 255, "TaskCount")
            dbComm.Parameters.Add("TaskNotes", OleDbType.VarChar, 255, "TaskNotes")
    
    
    
            dbComm.Parameters("CSRName").Value = ddName.Text
            dbComm.Parameters("DateofEntry").Value = txtDate.Text
            dbComm.Parameters("ScheduleStart").Value = txtSchStart.Text
            dbComm.Parameters("ScheduleEnd").Value = txtSchEnd.Text
            dbComm.Parameters("ProjectNumber").Value = ddProjNum.Text
            dbComm.Parameters("TaskCompleted").Value = ddTaskCompleted.Text
            dbComm.Parameters("TaskStart").Value = txtStart.Text
            dbComm.Parameters("TaskEnd").Value = txtEnd.Text
            dbComm.Parameters("TaskCount").Value = txtCount.Text
            dbComm.Parameters("TaskNotes").Value = txtNotes.Text
    
    
            Try
                objConnection.Open()
                dbComm.ExecuteNonQuery()
            Catch ex As Exception
                Response.Write(ex.Message)
                Response.End()
            Finally
                If objConnection.State = ConnectionState.Open Then
                    objConnection.Close()
                End If
            End Try
        End Sub

    Wednesday, May 25, 2016 7:50 PM

All replies

  • User1559292362 posted

    Hi Whamii,

    Send Multiple data to database

    Based on your requirement, it seems that we could use bulk insert to achieve it. and I create a simple demo as below for your reference.

    Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    
            Dim dt As DataTable = New DataTable()
            dt.Columns.Add("CSRName", System.Type.GetType("System.String"))
            dt.Columns.Add("DateofEntry", System.Type.GetType("System.String"))
            dt.Columns.Add("ScheduleStart", System.Type.GetType("System.String"))
            dt.Columns.Add("ScheduleEnd", System.Type.GetType("System.String"))
            For i As Integer = 0 To 7
                Dim dr As DataRow = dt.NewRow()
                dr("CSRName") = "CSRName" & i
                dr("DateofEntry") = "CSRName" & i
                dr("ScheduleStart") = "CSRName" & i
                dr("ScheduleEnd") = "CSRName" & i
                dt.Rows.Add(dr)
            Next
    
            Dim dataPath As String = Server.MapPath("~/Data/AccessDemo.accdb")
    
            Dim ConnString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & dataPath & "; Persist Security Info=False;"
    
            Dim SQL As String = "SELECT * FROM RetailTest WHERE ID=0"
            Dim INSERT As String = "INSERT INTO RetailTest (CSRName, DateofEntry, ScheduleStart, ScheduleEnd) " + "VALUES (@CSRName, @DateofEntry, @ScheduleStart, @ScheduleEnd)"
    
            Dim OleConn As New OleDbConnection(ConnString)
            Dim OleAdp As New OleDbDataAdapter(SQL, OleConn)
            OleAdp.InsertCommand = New OleDbCommand(INSERT)
            OleAdp.InsertCommand.Parameters.Add("@CSRName", OleDbType.VarChar, 255, "CSRName")
            OleAdp.InsertCommand.Parameters.Add("@DateofEntry", OleDbType.VarChar, 255, "DateofEntry")
            OleAdp.InsertCommand.Parameters.Add("@ScheduleStart", OleDbType.VarChar, 255, "ScheduleStart")
            OleAdp.InsertCommand.Parameters.Add("@ScheduleEnd", OleDbType.VarChar, 255, "ScheduleEnd")
            OleAdp.InsertCommand.Connection = OleConn
            OleAdp.InsertCommand.Connection.Open()
            OleAdp.Update(dt)
            OleAdp.InsertCommand.Connection.Close()
    
        End Sub

    Best regards,

    Cole Wu

    Thursday, May 26, 2016 5:14 AM
  • User1939751242 posted

    Thanks for the reply Cole. The code works good except now it appears to run through the form, grabs the first set of data from the form but ignores the rest. Here is what the rest looks like when entered into the database.

    <tfoot></tfoot>
    RetailTest
    ID CSRName DateofEntry ScheduleStart ScheduleEnd ProjectNumber TaskCompleted TaskStart TaskEnd TaskCount TaskNotes
    5 CSRName0 DateofEntry0 ScheduleStart0 ScheduleEnd0 ProjectNumber0 TaskCompleted0 TaskStart0 TaskEnd0 TaskCount0 TaskNotes0

       

        Protected Sub DBUpdate()
    
            Dim dt As DataTable = New DataTable()
            dt.Columns.Add("CSRName", System.Type.GetType("System.String"))
            dt.Columns.Add("DateofEntry", System.Type.GetType("System.String"))
            dt.Columns.Add("ScheduleStart", System.Type.GetType("System.String"))
            dt.Columns.Add("ScheduleEnd", System.Type.GetType("System.String"))
            dt.Columns.Add("ProjectNumber", System.Type.GetType("System.String"))
            dt.Columns.Add("TaskCompleted", System.Type.GetType("System.String"))
            dt.Columns.Add("TaskStart", System.Type.GetType("System.String"))
            dt.Columns.Add("TaskEnd", System.Type.GetType("System.String"))
            dt.Columns.Add("TaskCount", System.Type.GetType("System.String"))
            dt.Columns.Add("TaskNotes", System.Type.GetType("System.String"))
           
               For i As Integer = 0 To 7
                Dim dr As DataRow = dt.NewRow()
                dr("CSRName") = "CSRName" & i
                dr("DateofEntry") = "DateofEntry" & i
                dr("ScheduleStart") = "ScheduleStart" & i
                dr("ScheduleEnd") = "ScheduleEnd" & i
                dr("ProjectNumber") = "ProjectNumber" & i
                dr("TaskCompleted") = "TaskCompleted" & i
                dr("TaskStart") = "TaskStart" & i
                dr("TaskEnd") = "TaskEnd" & i
                dr("TaskCount") = "TaskCount" & i
                dr("TaskNotes") = "TaskNotes" & i
                dt.Rows.Add(dr)
            Next
            Dim ConnString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\\server\server2\path\path2\CRCTest.accdb"
    
            Dim SQL As String = "SELECT * FROM RetailTest WHERE ID=0"
            Dim INSERT As String = "INSERT INTO RetailTest (CSRName, DateofEntry, ScheduleStart, ScheduleEnd, ProjectNumber, TaskCompleted, TaskStart, TaskEnd, TaskCount, TaskNotes) " + "VALUES (@CSRName, @DateofEntry, @ScheduleStart, @ScheduleEnd, @ProjectNumber, @TaskCompleted, @TaskStart, @TaskEnd, @TaskCount, @TaskNotes )"
    
            Dim OleConn As New OleDbConnection(ConnString)
            Dim OleAdp As New OleDbDataAdapter(Sql, OleConn)
            OleAdp.InsertCommand = New OleDbCommand(INSERT)
            OleAdp.InsertCommand.Parameters.Add("@CSRName", OleDbType.VarChar, 255, "CSRName")
            OleAdp.InsertCommand.Parameters.Add("@DateofEntry", OleDbType.VarChar, 255, "DateofEntry")
            OleAdp.InsertCommand.Parameters.Add("@ScheduleStart", OleDbType.VarChar, 255, "ScheduleStart")
            OleAdp.InsertCommand.Parameters.Add("@ScheduleEnd", OleDbType.VarChar, 255, "ScheduleEnd")
            OleAdp.InsertCommand.Parameters.Add("@ProjectNumber", OleDbType.VarChar, 255, "ProjectNumber")
            OleAdp.InsertCommand.Parameters.Add("@TaskCompleted", OleDbType.VarChar, 255, "TaskCompleted")
            OleAdp.InsertCommand.Parameters.Add("@TaskStart", OleDbType.VarChar, 255, "TaskStart")
            OleAdp.InsertCommand.Parameters.Add("@TaskEnd", OleDbType.VarChar, 255, "TaskEnd")
            OleAdp.InsertCommand.Parameters.Add("@TaskCount", OleDbType.VarChar, 255, "TaskCount")
            OleAdp.InsertCommand.Parameters.Add("@TaskNotes", OleDbType.VarChar, 255, "TaskNotes")
            OleAdp.InsertCommand.Connection = OleConn
            OleAdp.InsertCommand.Connection.Open()
            OleAdp.Update(dt)
            OleAdp.InsertCommand.Connection.Close()
    
        End Sub

    Thursday, May 26, 2016 6:19 PM
  • User1559292362 posted

    Hi Whamii,

    Thanks for the reply Cole. The code works good except now it appears to run through the form, grabs the first set of data from the form but ignores the rest. Here is what the rest looks like when entered into the database.

    I create a simple by using your code, it seems that it works well, could you please provide a simple demo via OneDrive, so that we could reproduce your issue on my side and try to find a solution for you.

    Best regards,

    Cole Wu

    Saturday, May 28, 2016 2:58 AM
  • User1939751242 posted

    Cole,

    So my users go to this web form, on the web form I have a series of textboxes and drop downs. Users have a choice to submit one to five entries at once. If the users choose more than one entry, I need all of the data to be submitted, regardless of how many entries are entered. With the code above, it will grab the data from the first entry and not any entry beyond that. So if I enter data for 2 entries, it will grab the data for the first entry but enter generic data for all other entries. In my example in the above message, I entered data on the form into all fields for 2 entries, it grabbed the data for the first entry but ignored the second entry. I am not sure why it missed the second set of data.

    I am not sure about OneDrive so that's why I was not able to do what you asked me to do.

    Wednesday, June 1, 2016 4:14 PM
  • User1559292362 posted

    Hi Whamii,

    I am not sure about OneDrive so that's why I was not able to do what you asked me to do.

    Could you please post the complete aspx page and related code behind code on here?

    Best regards,

    Cole Wu

    Monday, June 6, 2016 5:20 AM
  • User1939751242 posted
    default.aspx
    
    
    
    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
    
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>CRC Database Form</title>
        <style type="text/css">
            .auto-style1 {
                margin-left: 0px;
            }
            .auto-style2 {}
            .auto-style3 {}
            .auto-style4 {}
            .auto-style5 {
                text-align: center;
            }
            .auto-style6 {
                text-align: center;
            }
            .auto-style7 {
                text-align: center;
            }
        </style>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        
            CRC Form</div>
            <p>
                &nbsp;</p>
            <p>
                <asp:Label ID="lblName" runat="server" Text="Name"></asp:Label>
    &nbsp;
                <asp:DropDownList ID="ddName" runat="server" DataSourceID="CRCAgentName" DataTextField="Employee Name" DataValueField="Employee Name">
                </asp:DropDownList>
                <asp:SqlDataSource ID="CRCAgentName" runat="server" ConnectionString="<%$ ConnectionStrings:CRC ApplicationRet %>" ProviderName="<%$ ConnectionStrings:CRC ApplicationRet.ProviderName %>" SelectCommand="SELECT Main_Emp!EMP_LAST_NAME &amp; &quot;, &quot; &amp; Main_Emp!EMP_FIRST_NAME AS [Employee Name], Main_Emp.PRI_INDEX, Main_Emp.EMP_Active
    FROM Main_Emp
    WHERE (((Main_Emp.EMP_Active)=Yes))
    ORDER BY Main_Emp!EMP_LAST_NAME &amp; &quot;, &quot; &amp; Main_Emp!EMP_FIRST_NAME;"></asp:SqlDataSource>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <asp:Label ID="lblDate" runat="server" Text="Date"></asp:Label>
    &nbsp;
                <asp:TextBox ID="txtDate" runat="server" CssClass="auto-style4" Width="97px"></asp:TextBox>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <asp:Label ID="Label1" runat="server" Text="Sch Start"></asp:Label>
    &nbsp;&nbsp;
                <asp:TextBox ID="txtSchStart" runat="server" CssClass="auto-style1" Width="85px"></asp:TextBox>
    &nbsp;&nbsp;&nbsp;
                <asp:Label ID="lblSchEnd" runat="server" Text="Sch End"></asp:Label>
    &nbsp;
                <asp:TextBox ID="txtSchEnd" runat="server" Width="85px"></asp:TextBox>
            </p>
            <p>
                <asp:Label ID="lblPro" runat="server" Text="Project Number"></asp:Label>
    &nbsp;
                <asp:DropDownList ID="ddProjNum" runat="server" DataSourceID="CRCProjectNumber" DataTextField="Project_Number" DataValueField="Project_Number">
                </asp:DropDownList>
                <asp:SqlDataSource ID="CRCProjectNumber" runat="server" ConnectionString="<%$ ConnectionStrings:CRC ApplicationRet %>" ProviderName="<%$ ConnectionStrings:CRC ApplicationRet.ProviderName %>" SelectCommand="SELECT AP_Account_Select.Project_Number, AP_Account_Select.Account_Name
    FROM AP_Account_Select
    ORDER BY AP_Account_Select.[Account_Name];"></asp:SqlDataSource>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <asp:Label ID="lblTaskCompleted" runat="server" Text="Task Completed"></asp:Label>
    &nbsp;
                <asp:DropDownList ID="ddTaskCompleted" runat="server" DataSourceID="CRCTask" DataTextField="Task_Name" DataValueField="Task_Name">
                </asp:DropDownList>
                <asp:SqlDataSource ID="CRCTask" runat="server" ConnectionString="<%$ ConnectionStrings:CRC ApplicationRet %>" ProviderName="<%$ ConnectionStrings:CRC ApplicationRet.ProviderName %>" SelectCommand="SELECT AP_TaskList_Select.Task_Name, AP_TaskList_Select.Task_Code, AP_TaskList_Select.ActiveTask
    FROM AP_TaskList_Select
    WHERE (((AP_TaskList_Select.ActiveTask)=Yes))
    ORDER BY AP_TaskList_Select.Task_Name;
    "></asp:SqlDataSource>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <asp:Label ID="Label2" runat="server" Text="Start"></asp:Label>
                <asp:TextBox ID="txtStart" runat="server"></asp:TextBox>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <asp:Label ID="lblEnd" runat="server" Text="End"></asp:Label>
    &nbsp;
                <asp:TextBox ID="txtEnd" runat="server"></asp:TextBox>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <asp:Label ID="lblCount" runat="server" Text="Count"></asp:Label>
                <asp:TextBox ID="txtCount" runat="server" CssClass="auto-style2" Width="35px"></asp:TextBox>
            </p>
            <p>
                <asp:Label ID="lblNotes" runat="server" Text="Notes"></asp:Label>
            </p>
            <p>
                <asp:TextBox ID="txtNotes" runat="server" CssClass="auto-style3" TextMode="MultiLine" Width="442px"></asp:TextBox>
            </p>
            <p>
                &nbsp;</p>
            <p>
                &nbsp;</p>
            <p>
                <asp:Label ID="lblName0" runat="server" Text="Name"></asp:Label>
    &nbsp;
                <asp:DropDownList ID="ddName2" runat="server" DataSourceID="CRCAgentName0" DataTextField="Employee Name" DataValueField="Employee Name">
                </asp:DropDownList>
                <asp:SqlDataSource ID="CRCAgentName0" runat="server" ConnectionString="<%$ ConnectionStrings:CRC ApplicationRet %>" ProviderName="<%$ ConnectionStrings:CRC ApplicationRet.ProviderName %>" SelectCommand="SELECT Main_Emp!EMP_LAST_NAME &amp; &quot;, &quot; &amp; Main_Emp!EMP_FIRST_NAME AS [Employee Name], Main_Emp.PRI_INDEX, Main_Emp.EMP_Active
    FROM Main_Emp
    WHERE (((Main_Emp.EMP_Active)=Yes))
    ORDER BY Main_Emp!EMP_LAST_NAME &amp; &quot;, &quot; &amp; Main_Emp!EMP_FIRST_NAME;"></asp:SqlDataSource>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <asp:Label ID="lblDate0" runat="server" Text="Date"></asp:Label>
    &nbsp;
                <asp:TextBox ID="txtDate2" runat="server" CssClass="auto-style4" Width="97px"></asp:TextBox>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <asp:Label ID="Label3" runat="server" Text="Sch Start"></asp:Label>
    &nbsp;&nbsp;
                <asp:TextBox ID="txtSchStart2" runat="server" CssClass="auto-style1" Width="85px"></asp:TextBox>
    &nbsp;&nbsp;&nbsp;
                <asp:Label ID="lblSchEnd0" runat="server" Text="Sch End"></asp:Label>
    &nbsp;
                <asp:TextBox ID="txtSchEnd2" runat="server" Width="85px"></asp:TextBox>
            </p>
            <p>
                <asp:Label ID="lblPro0" runat="server" Text="Project Number"></asp:Label>
    &nbsp;
                <asp:DropDownList ID="ddProjNum2" runat="server" DataSourceID="CRCProjectNumber0" DataTextField="Project_Number" DataValueField="Project_Number">
                </asp:DropDownList>
                <asp:SqlDataSource ID="CRCProjectNumber0" runat="server" ConnectionString="<%$ ConnectionStrings:CRC ApplicationRet %>" ProviderName="<%$ ConnectionStrings:CRC ApplicationRet.ProviderName %>" SelectCommand="SELECT AP_Account_Select.Project_Number, AP_Account_Select.Account_Name
    FROM AP_Account_Select
    ORDER BY AP_Account_Select.[Account_Name];"></asp:SqlDataSource>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <asp:Label ID="lblTaskCompleted0" runat="server" Text="Task Completed"></asp:Label>
    &nbsp;
                <asp:DropDownList ID="ddTaskCompleted2" runat="server" DataSourceID="CRCTask0" DataTextField="Task_Name" DataValueField="Task_Name">
                </asp:DropDownList>
                <asp:SqlDataSource ID="CRCTask0" runat="server" ConnectionString="<%$ ConnectionStrings:CRC ApplicationRet %>" ProviderName="<%$ ConnectionStrings:CRC ApplicationRet.ProviderName %>" SelectCommand="SELECT AP_TaskList_Select.Task_Name, AP_TaskList_Select.Task_Code, AP_TaskList_Select.ActiveTask
    FROM AP_TaskList_Select
    WHERE (((AP_TaskList_Select.ActiveTask)=Yes))
    ORDER BY AP_TaskList_Select.Task_Name;
    "></asp:SqlDataSource>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <asp:Label ID="Label4" runat="server" Text="Start"></asp:Label>
                <asp:TextBox ID="txtStart2" runat="server"></asp:TextBox>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <asp:Label ID="lblEnd0" runat="server" Text="End"></asp:Label>
    &nbsp;
                <asp:TextBox ID="txtEnd2" runat="server"></asp:TextBox>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <asp:Label ID="lblCount0" runat="server" Text="Count"></asp:Label>
                <asp:TextBox ID="txtCount2" runat="server" CssClass="auto-style2" Width="35px"></asp:TextBox>
            </p>
            <p>
                <asp:Label ID="lblNotes0" runat="server" Text="Notes"></asp:Label>
            </p>
            <p>
                <asp:TextBox ID="txtNotes2" runat="server" CssClass="auto-style3" TextMode="MultiLine" Width="442px"></asp:TextBox>
            </p>
            <p>
                &nbsp;</p>
            <p class="auto-style7">
                <asp:Button ID="Button1" runat="server" CssClass="auto-style6" Text="Reset" />
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <asp:Button ID="btnSubmit" runat="server" CssClass="auto-style5" Text="Submit" />
            </p>
        </form>
    </body>
    </html>
    
    default.aspx.vb
    
    Imports System.Data.OleDb
    Imports System.Data
    
    Partial Class _Default
        Inherits System.Web.UI.Page
    
        Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
            txtDate.Text = System.DateTime.Now.ToShortDateString()
    
        End Sub
    
        Protected Sub btnSubmit_Click(sender As Object, e As EventArgs) Handles btnSubmit.Click
            
            DBUpdate()
    
        End Sub
    
        
        Protected Sub DBUpdate()
    
            Dim dt As DataTable = New DataTable()
            dt.Columns.Add("CSRName", System.Type.GetType("System.String"))
            dt.Columns.Add("DateofEntry", System.Type.GetType("System.String"))
            dt.Columns.Add("ScheduleStart", System.Type.GetType("System.String"))
            dt.Columns.Add("ScheduleEnd", System.Type.GetType("System.String"))
            dt.Columns.Add("ProjectNumber", System.Type.GetType("System.String"))
            dt.Columns.Add("TaskCompleted", System.Type.GetType("System.String"))
            dt.Columns.Add("TaskStart", System.Type.GetType("System.String"))
            dt.Columns.Add("TaskEnd", System.Type.GetType("System.String"))
            dt.Columns.Add("TaskCount", System.Type.GetType("System.String"))
            dt.Columns.Add("TaskNotes", System.Type.GetType("System.String"))
            For i As Integer = 0 To 7
                Dim dr As DataRow = dt.NewRow()
                dr("CSRName") = "CSRName" & i
                dr("DateofEntry") = "DateofEntry" & i
                dr("ScheduleStart") = "ScheduleStart" & i
                dr("ScheduleEnd") = "ScheduleEnd" & i
                dr("ProjectNumber") = "ProjectNumber" & i
                dr("TaskCompleted") = "TaskCompleted" & i
                dr("TaskStart") = "TaskStart" & i
                dr("TaskEnd") = "TaskEnd" & i
                dr("TaskCount") = "TaskCount" & i
                dr("TaskNotes") = "TaskNotes" & i
                dt.Rows.Add(dr)
            Next
    
            ' Dim dataPath As String = Server.MapPath("\\copufnp01\Customer Response Center\CRC Database\Database Applications\CRCTest.accdb")
    
            Dim ConnString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=\\copufnp01\Customer Response Center\CRC Database\Database Applications\CRCTest.accdb"
    
            Dim SQL As String = "SELECT * FROM RetailTest WHERE ID=0"
            Dim INSERT As String = "INSERT INTO RetailTest (CSRName, DateofEntry, ScheduleStart, ScheduleEnd, ProjectNumber, TaskCompleted, TaskStart, TaskEnd, TaskCount, TaskNotes) " + "VALUES (@CSRName, @DateofEntry, @ScheduleStart, @ScheduleEnd, @ProjectNumber, @TaskCompleted, @TaskStart, @TaskEnd, @TaskCount, @TaskNotes )"
    
            Dim OleConn As New OleDbConnection(ConnString)
            Dim OleAdp As New OleDbDataAdapter(Sql, OleConn)
            OleAdp.InsertCommand = New OleDbCommand(INSERT)
            OleAdp.InsertCommand.Parameters.Add("@CSRName", OleDbType.VarChar, 255, "CSRName")
            OleAdp.InsertCommand.Parameters.Add("@DateofEntry", OleDbType.VarChar, 255, "DateofEntry")
            OleAdp.InsertCommand.Parameters.Add("@ScheduleStart", OleDbType.VarChar, 255, "ScheduleStart")
            OleAdp.InsertCommand.Parameters.Add("@ScheduleEnd", OleDbType.VarChar, 255, "ScheduleEnd")
            OleAdp.InsertCommand.Parameters.Add("@ProjectNumber", OleDbType.VarChar, 255, "ProjectNumber")
            OleAdp.InsertCommand.Parameters.Add("@TaskCompleted", OleDbType.VarChar, 255, "TaskCompleted")
            OleAdp.InsertCommand.Parameters.Add("@TaskStart", OleDbType.VarChar, 255, "TaskStart")
            OleAdp.InsertCommand.Parameters.Add("@TaskEnd", OleDbType.VarChar, 255, "TaskEnd")
            OleAdp.InsertCommand.Parameters.Add("@TaskCount", OleDbType.VarChar, 255, "TaskCount")
            OleAdp.InsertCommand.Parameters.Add("@TaskNotes", OleDbType.VarChar, 255, "TaskNotes")
            OleAdp.InsertCommand.Connection = OleConn
            OleAdp.InsertCommand.Connection.Open()
            OleAdp.Update(dt)
            OleAdp.InsertCommand.Connection.Close()
    
        End Sub
    
    
    End Class
    


    Monday, June 6, 2016 6:11 PM