User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP.NET section within the Web Development category of DaniWeb, a massive community of 403,221 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,063 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting

need help with sql database in asp.net using VB

Join Date: Jan 2006
Location: Its the internet... i am everywhere lol
Posts: 274
Reputation: f1 fan is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 10
f1 fan f1 fan is offline Offline
Posting Whiz in Training

Re: need help with sql database in asp.net using VB

  #5  
Mar 23rd, 2007
OK
You can get webdeveloper express which is free and makes it a lot easier.
the code below has a grid view which lets me list, edit and delete items in the grid (it could select too but i have no need of that in this example).
grid views dont allow news rows so i use a details view (below it) which is in default mode of insert.
Both are bound to the sqldatasource which you see below them. In my case i have the connection string elsewhere in my app which it knows to go find by the <%$ ... %> tags. You can use stored procs etc but i included this code for you to see
Hope it helps you
    <asp:GridView ID="GridView1" runat="server" AllowPaging="True"
        AutoGenerateColumns="False" DataKeyNames="aID" DataSourceID="SqlDataSource1" Caption="Collections" Width="300px">
        <Columns>
            <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
            <asp:BoundField DataField="aID" HeaderText="aID" ReadOnly="True" SortExpression="aID" Visible="False" />
            <asp:BoundField DataField="CollectionName" HeaderText="Collection Name" SortExpression="CollectionName" />
        </Columns>
    </asp:GridView><br /><br />
    <asp:DetailsView ID="DetailsView1" runat="server" AllowPaging="True" AutoGenerateRows="False"
        DataKeyNames="aID" DataSourceID="SqlDataSource1" DefaultMode="Insert" Height="50px"
        Width="300px" Caption="Add New Collection">
        <Fields>
            <asp:BoundField DataField="aID" HeaderText="aID" ReadOnly="True" SortExpression="aID" Visible="False" />
            <asp:BoundField DataField="CollectionName" HeaderText="Collection Name" SortExpression="CollectionName" />
            <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" ShowInsertButton="True" />
        </Fields>
    </asp:DetailsView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConflictDetection="CompareAllValues"
        ConnectionString="<%$ ConnectionStrings:CHComConnectionString %>" DeleteCommand="DELETE FROM [Collections] WHERE [aID] = @original_aID AND [CollectionName] = @original_CollectionName"
        InsertCommand="INSERT INTO [Collections] ([aID], [CollectionName]) VALUES (newid(), @CollectionName)"
        OldValuesParameterFormatString="original_{0}" SelectCommand="SELECT [aID], [CollectionName] FROM [Collections] order by [CollectionName]"
        UpdateCommand="UPDATE [Collections] SET [CollectionName] = @CollectionName WHERE [aID] = @original_aID AND [CollectionName] = @original_CollectionName">
        <DeleteParameters>
            <asp:Parameter Name="original_aID" Type="Object" />
            <asp:Parameter Name="original_CollectionName" Type="String" />
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter Name="CollectionName" Type="String" />
            <asp:Parameter Name="original_aID" Type="Object" />
            <asp:Parameter Name="original_CollectionName" Type="String" />
        </UpdateParameters>
        <InsertParameters>
            <asp:Parameter Name="CollectionName" Type="String" />
        </InsertParameters>
    </asp:SqlDataSource>
Reply With Quote  
All times are GMT -4. The time now is 5:07 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC