locked
vwd 2008 express with access - "Add" button RRS feed

  • Question

  • User-392230853 posted

     Tried to make the "add" button working, it is only half working. I can add the new record form the textboxes, but I will get the error on the datasource, datasourceID, THEN i CHANGED THE DATASOURCE TO DATASORUCEID, i GOT THE OTHER ERROR THE "dt" couldn't transfer to string, how to fix this? The other question is, the gridview in the vwd 2008 express won't properly doing the refresh? Thanks.

    * HALF WORKING - i DON'T SEE THE RECORD TO ADD IN and Refresh, but after RERUN THIS PROGRAM.

    This program;
    One "add" button
    Two textbox to enter the new records

     <asp:GridView ID="GridView1" runat="server" AllowSorting="True"  
    AutoGenerateColumns="False" DataKeyNames="id" DataSourceID="AccessDataSource1"  
    BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Vertical" Width="779px"> 
    <RowStyle BackColor="#EEEEEE" ForeColor="Black" />
    Protected Sub Button4_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button4.Click 
     
    Dim con1 As New OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0;Data Source=C:\Users\user\Desktop\honor.mdb") 
             
           Dim sqlinsert As String 
     
            sqlinsert = "INSERT INTO sysdep (sysaccount,syspw)" & _ 
              "VALUES(@sysaccount, @syspw)" 
     
            Dim cmd As New OleDbCommand(sqlinsert, con1) 
     
        cmd.Parameters.Add(New OleDbParameter("@sysaccount", TextBox1.Text)) 
            cmd.Parameters.Add(New OleDbParameter("@syspw", TextBox2.Text)) 
     
            Try 
                con1.Open() 
                cmd.ExecuteNonQuery() 
            Catch ex As OleDbException 
                MsgBox(ex.Message, MsgBoxStyle.Critical, "Web Message") 
            Catch ex As InvalidOperationException 
                MsgBox(ex.Message, MsgBoxStyle.Critical, "Web Message") 
            Catch ex As Exception 
                MsgBox(ex.Message, MsgBoxStyle.Critical, "Web Message") 
            End Try 
     
            con1.Close() 
     
            RefreshDGV() 
        End Sub 
         
    Private Sub RefreshDGV() 
             
    Dim con1 As New OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0;Data Source=C:\Users\user\Desktop\honor.mdb") 
            Dim sql As String 
            sql = "SELECT * FROM sysdep" 
            Dim adapter As New OleDbDataAdapter(sql, con1) 
            Dim dt As New DataTable("sysdep") 
            adapter.Fill(dt) 
            GridView1.DataSource = dt ******> ERROR MESSAGE - DataSoruce,DatasourceID, To remove  
        End Sub



    I really don't know how to fix these DataSource/DataSourceID, I did try something else, but so far, just not working, thanks.

    Thursday, June 3, 2010 10:49 PM

Answers

  • User-821857111 posted

    You cannot set the DataSource of a GridView or other control if you have set the DataSourceID property in the markup. At the moment, you have this in the top part of your code:

    DataSourceID="AccessDataSource1"

    But there is no AccessDataSource shown. Try removing it.


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, June 4, 2010 1:59 AM