DropDown and Textbox data to ms access and gridview display in C# ASP.NET -


i have dropdown , textbox .i hardcoded values dropdown ,and textbox values entered user on webpage.i want insert data first ms access , populate gridview ms access in same page.

problem not updating ms access table , gridview getting loaded on webpage not getting updated.please new c# coding.

following code using-

code dropdown-

<asp:dropdownlist id="dropdownlist1" runat="server" height="16px" width="113px">    <asp:listitem value="0">select class</asp:listitem>    <asp:listitem value="class 0">class 0</asp:listitem>    <asp:listitem value="class 1">class 1</asp:listitem>    <asp:listitem value="class 2">class 2</asp:listitem>    <asp:listitem value="class 3">class 3</asp:listitem>    asp:listitem value="class 4">class 4</asp:listitem>  </asp:dropdownlist>   using system.data.oledb; using system.data;  public partial class _default : system.web.ui.page { oledbconnection con; oledbcommand cmd;  protected void button1_click(object sender, eventargs e) {   using (con = new oledbconnection(@"provider=microsoft.ace.oledb.12.0;" +    @"data source=c:\users\gandhs3\desktop\excel.accdb"))         {             cmd = new oledbcommand();             cmd.commandtext = "insert classlevel([class],[18th])values(@class, @th)";              cmd.parameters.add("@class", oledbtype.varchar).value =    dropdownlist1.selecteditem.text;             cmd.parameters.add("@th", oledbtype.varchar).value = textbox2.text;              cmd.connection = con;             con.open();            cmd.executenonquery();             con.close();             dropdownlist1.text = "";             textbox2.text = "";          }         binduserdetails();     }     protected void binduserdetails()     {     //dataset ds = new dataset();         datatable dt;     string strquery = "select * classlevel";     using (con = new oledbconnection(@"provider=microsoft.ace.oledb.12.0;" + @"data source=c:\users\gandhs3\desktop\excel.accdb"))     {     using (cmd = new oledbcommand(strquery, con))     {         con.open();      oledbdataadapter da = new oledbdataadapter(cmd);     dt = new datatable();     da.fill(dt);     }     }     gridview1.datasource=dt;     gridview1.databind();     } 

}

code dropdown-

<asp:dropdownlist id="dropdownlist1" runat="server" height="16px" width="113px">      <asp:listitem value="0">select class</asp:listitem>     <asp:listitem value="class 0">class 0</asp:listitem>     <asp:listitem value="class 1">class 1</asp:listitem>     <asp:listitem value="class 2">class 2</asp:listitem>     <asp:listitem value="class 3">class 3</asp:listitem>     <asp:listitem value="class 4">class 4</asp:listitem> </asp:dropdownlist>     


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -