7 Replies - 892 Views - Last Post: 10 June 2010 - 06:52 PM Rate Topic: -----

#1 Needanswer  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 61
  • Joined: 27-January 10

questions on the vwd 2008 express with access

Posted 07 June 2010 - 06:03 PM

I have a gridview with access and built with "select","edit" & "delete", the outside under gridview with the "add","cancel" buttons.


details:

select edit delet id name etc.


Textbox1
Textbox2

add cancel



ALL THE BUILT SELECT,EDIT,DELETE WRER WORKING, ONLY THE "ADD" BUTTON WAS NOT WORKING. So, I rebind the gridview with access - GOT THE DATASOURCE/DATASOURCEID PROBLEM, I delete the the datasourceid in the html, the "add" button actually is working and will refresh the gridview.

details:
&nbsp;<asp:GridView ID="GridView1" runat="server" AllowSorting="True" 
AutoGenerateColumns="False" DataKeyNames="id"  
BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Vertical" Width="779px">
<RowStyle BackColor="#EEEEEE" ForeColor="Black" /> 


 
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            BindGridView()
        End If

    End Sub
    Private Sub BindGridView()
        ' Code to retrieve records from database and fill it in a DataTable and Bind it to GridView
        Dim dt As DataTable = New DataTable()
        Dim conn As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0;Data Source=C:\Users\user\Desktop\honor.mdb")
        Dim da As OleDbDataAdapter = New OleDbDataAdapter("SELECT * FROM Sysdep", conn)
        conn.Open()
        da.Fill(dt)
        da.Dispose()
        conn.Close()

        GridView1.DataSource = dt
        GridView1.DataBind()
    End Sub

    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")
        Catch ex As InvalidOperationException
            MsgBox(ex.Message, MsgBoxStyle.Critical,"web")
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Critical,"web")
        End Try

        con1.Close()
        BindGridView()

    End Sub



BUT NOW THE BUILT THE EDIT,DELETE ARE NOT WORKING - ERRORS,GRIDVIEW1 NOT HANDLE THE ROWEDITING, ROWDELETING,how to fix them?

Thanks.

This post has been edited by Needanswer: 08 June 2010 - 05:46 PM


Is This A Good Question/Topic? 0
  • +

Replies To: questions on the vwd 2008 express with access

#2 Frinavale  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 205
  • View blog
  • Posts: 776
  • Joined: 03-June 10

Re: questions on the vwd 2008 express with access

Posted 08 June 2010 - 07:28 AM

I took the code that you posted and made it more legible so that I can see what is going on:
<asp:GridView ID="GridView1" runat="server" AllowSorting="True" 
  AutoGenerateColumns="False" 
  DataKeyNames="id"  
  BackColor="White" 
  BorderColor="#999999"
  BorderStyle="None"
  BorderWidth="1px"
  CellPadding="3"
  GridLines="Vertical"
  Width="779px">

  <RowStyle BackColor="#EEEEEE" ForeColor="Black" />

  &nbsp;
  <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" />


You have 2 GridView's posted here...neither of them has an ending </asp:GridView> tag and so I'm not sure how your code is even working properly. You should be getting errors if this is actually what you have.

By the sounds of it, you have developed methods that handle each event. You can explicitly specify the methods that get called for each event in the code markup for the GridView. I'm not sure which GridView you want to link up to the Add/Edit/Delete so I'm just going to show you how to do this in your first GridView:
<asp:GridView ID="GridView1" runat="server" AllowSorting="True" 
  AutoGenerateColumns="False" 
  DataKeyNames="id"  
  OnRowDeleting="theMethodToCallWhenDeletingARow()"
  OnRowEditing="theMethodToCallWhenEditingARow()"
  BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Vertical" Width="779px">

  <RowStyle BackColor="#EEEEEE" ForeColor="Black" />
</asp:GridView>


-Frinny
Was This Post Helpful? 0
  • +
  • -

#3 Needanswer  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 61
  • Joined: 27-January 10

Re: questions on the vwd 2008 express with access

Posted 08 June 2010 - 05:59 PM

View PostFrinavale, on 08 June 2010 - 06:28 AM, said:

I took the code that you posted and made it more legible so that I can see what is going on:
<asp:GridView ID="GridView1" runat="server" AllowSorting="True" 
  AutoGenerateColumns="False" 
  DataKeyNames="id"  
  BackColor="White" 
  BorderColor="#999999"
  BorderStyle="None"
  BorderWidth="1px"
  CellPadding="3"
  GridLines="Vertical"
  Width="779px">

  <RowStyle BackColor="#EEEEEE" ForeColor="Black" />



You have 2 GridView's posted here...neither of them has an ending </asp:GridView> tag and so I'm not sure how your code is even working properly. You should be getting errors if this is actually what you have.

By the sounds of it, you have developed methods that handle each event. You can explicitly specify the methods that get called for each event in the code markup for the GridView. I'm not sure which GridView you want to link up to the Add/Edit/Delete so I'm just going to show you how to do this in your first GridView:
<asp:GridView ID="GridView1" runat="server" AllowSorting="True" 
  AutoGenerateColumns="False" 
  DataKeyNames="id"  
  OnRowDeleting="theMethodToCallWhenDeletingARow()"
  OnRowEditing="theMethodToCallWhenEditingARow()"
  BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Vertical" Width="779px">

  <RowStyle BackColor="#EEEEEE" ForeColor="Black" />
</asp:GridView>


-Frinny



Thanks Frinny, actually I got double past, a mistake on the html. I got them out already, except the gridview1_rowupdating.
Was This Post Helpful? 0
  • +
  • -

#4 Frinavale  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 205
  • View blog
  • Posts: 776
  • Joined: 03-June 10

Re: questions on the vwd 2008 express with access

Posted 08 June 2010 - 08:50 PM

I'm not sure I understand you...What's wrong with the RowUpdating? Or did you solve your problem already?
Was This Post Helpful? 0
  • +
  • -

#5 Needanswer  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 61
  • Joined: 27-January 10

Re: questions on the vwd 2008 express with access

Posted 08 June 2010 - 11:45 PM

View PostFrinavale, on 08 June 2010 - 07:50 PM, said:

I'm not sure I understand you...What's wrong with the RowUpdating? Or did you solve your problem already?



All buttons working, rowupdating not ready?

 <asp:GridView ID="GridView1" runat="server" AllowSorting="True" 
        AutoGenerateColumns="False" DataKeyNames="id"  
            BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="1px" 
            CellPadding="3" GridLines="Vertical" >
            <RowStyle BackColor="#EEEEEE" ForeColor="Black"/>
            <Columns>
                <asp:TemplateField ShowHeader="False">
                    <EditItemTemplate>
                        <asp:Button ID="Button1" runat="server" CausesValidation="True" 
                            CommandName="Update" Text="Update" />
                        &nbsp;<asp:Button ID="Button2" runat="server" CausesValidation="False" 
                            CommandName="Cancel" Text="Cancel" />
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Button ID="Button1" runat="server" CausesValidation="False" 
                            CommandName="Edit" Text="Edit" />
                        &nbsp;<asp:Button ID="Button2" runat="server" CausesValidation="False" 
                            CommandName="Select" Text="Select" />
                        &nbsp;<asp:Button ID="Button3" runat="server" CausesValidation="False" 
                            CommandName="Delete" Text="Cancel" OnClientClick="return confirm('Are you sure');"/>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="id" HeaderText="id" InsertVisible="False" 
                    ReadOnly="True" SortExpression="id" Visible="False" />
                <asp:BoundField DataField="sysaccount" HeaderText="sysaccount" 
                    SortExpression="sysaccount" />
                <asp:BoundField DataField="syspw" HeaderText="syspw" SortExpression="syspw" />
                <asp:BoundField DataField="log" HeaderText="log" SortExpression="log" />
            </Columns>
            <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
            <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
            <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
            <HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
            <AlternatingRowStyle BackColor="#DCDCDC" />
        </asp:GridView>
    <br />
    <br />
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <br />
        <br />
&nbsp;&nbsp;&nbsp;
        <br />
        <br />
        <br />
        <br />
&nbsp;&nbsp;
        <asp:Label ID="Label3" runat="server" Text="System Manager"></asp:Label>
&nbsp;&nbsp;&nbsp;
        <asp:TextBox ID="TextBox1" runat="server" Height="26px"></asp:TextBox>
        <br />
        <br />
        <br />
&nbsp;&nbsp;
        <asp:Label ID="Label4" runat="server" Text="Password"></asp:Label>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <asp:TextBox ID="TextBox2" runat="server" Height="26px"></asp:TextBox>
&nbsp;<br />
        <br />
        <br />
        <br />
&nbsp;&nbsp;&nbsp;
        <asp:Button ID="Button4" runat="server" 
            style="font-size: large; font-family: Times New Roman; font-weight: 700" Text="Add" />
&nbsp;&nbsp;
        <asp:Button ID="Button5" runat="server" 
            style="font-size: large; font-family: Times New Roman; font-weight: 700" Text="Cancel" />
    &nbsp;



Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GridView1.RowUpdating
        Dim sqlupdate As String
        Dim con1 As New OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0;Data Source=C:\Users\user\Desktop\honor.mdb")
        sqlupdate = "UPDATE sysdep SET sysaccount= @sysaccount, syspw= @syspw WHERE id= @id"

        Dim cmd1 As New OleDbCommand(sqlupdate, con1)

        Dim id As String = (GridView1.Rows(e.RowIndex).Cells(0).ToString)

        Dim account As String = (GridView1.Rows(e.RowIndex).Cells(1).ToString)
        Dim pw As String = (GridView1.Rows(e.RowIndex).Cells(2).ToString)


        cmd1.Parameters.Add(New OleDbParameter("@sysaccount", account))
        cmd1.Parameters.Add(New OleDbParameter("@syspw", pw))
        cmd1.Parameters.Add(New OleDbParameter("@id", id))

        Try
            con1.Open()
            cmd1.ExecuteNonQuery()
        Catch ex As OleDbException
            MsgBox(ex.Message, MsgBoxStyle.Critical, "Web")
        Catch ex As InvalidOperationException
            MsgBox(ex.Message, MsgBoxStyle.Critical, "Web")
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Critical, "Web")
        End Try

        con1.Close()

        GridView1.EditIndex = -1

        BindGridView()
    End Sub


This post has been edited by Needanswer: 08 June 2010 - 11:47 PM

Was This Post Helpful? 0
  • +
  • -

#6 Frinavale  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 205
  • View blog
  • Posts: 776
  • Joined: 03-June 10

Re: questions on the vwd 2008 express with access

Posted 09 June 2010 - 08:00 AM

View PostNeedanswer, on 08 June 2010 - 10:45 PM, said:

All buttons working, rowupdating not ready?


Does this mean that your method is not being reached?
Or maybe this means that your button-click code is being executed but your database isn't being updated?

Please describe the problem because simply posting the code is not very descriptive of what is wrong....I can't help you if I don't know what the problem is. I looked at the code but, I don't know what I'm supposed to be looking for because you haven't stated what's wrong.

-Frinny
Was This Post Helpful? 0
  • +
  • -

#7 Guest_needanswer*


Reputation:

Re: questions on the vwd 2008 express with access

Posted 09 June 2010 - 05:24 PM

View PostFrinavale, on 09 June 2010 - 07:00 AM, said:

View PostNeedanswer, on 08 June 2010 - 10:45 PM, said:

All buttons working, rowupdating not ready?


Does this mean that your method is not being reached?
Or maybe this means that your button-click code is being executed but your database isn't being updated?

Please describe the problem because simply posting the code is not very descriptive of what is wrong....I can't help you if I don't know what the problem is. I looked at the code but, I don't know what I'm supposed to be looking for because you haven't stated what's wrong.

-Frinny


There is no any error message, just won't get update.
Was This Post Helpful? 0

#8 Needanswer  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 61
  • Joined: 27-January 10

Re: questions on the vwd 2008 express with access

Posted 10 June 2010 - 06:52 PM

View Postneedanswer, on 09 June 2010 - 04:24 PM, said:

View PostFrinavale, on 09 June 2010 - 07:00 AM, said:

View PostNeedanswer, on 08 June 2010 - 10:45 PM, said:

All buttons working, rowupdating not ready?


Does this mean that your method is not being reached?
Or maybe this means that your button-click code is being executed but your database isn't being updated?

Please describe the problem because simply posting the code is not very descriptive of what is wrong....I can't help you if I don't know what the problem is. I looked at the code but, I don't know what I'm supposed to be looking for because you haven't stated what's wrong.

-Frinny


There is no any error message, just won't get update.


It is working now.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1