Click here to Skip to main content
15,897,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
protected void Submitbtn_Click(object sender, EventArgs e)
    {



        string connection_string = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\HILProject\project4\App_Data\adminlog.mdb";
        using (OleDbConnection cn = new OleDbConnection(connection_string))
        {
            cn.Open();
           
           
            String str = "select * from BasicDtl_tbl where UserName=" + usertxt.Text + "";
             OleDbCommand cmd = new OleDbCommand(str,cn);
           // cmd.Connection = cn;
           OleDbDataAdapter ad = new OleDbDataAdapter(cmd);
          System.Data.DataSet  ds = new System.Data.DataSet();
           ad.Fill(ds);

           Nattxt.Text = ds.Tables[0].Rows[0].ItemArray[2].ToString();
           apldposttxt.Text = ds.Tables[0].Rows[0].ItemArray[3].ToString();
           cn.Close();
        }
    }

error shown is
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
A page can have only one server-side Form tag.
Posted
Updated 3-Jun-14 19:35pm
v2
Comments
Ajith K Gatty 4-Jun-14 1:41am    
Hi Ashwini,
Use debugger to find the error. And from stack trace u can identify the error as well.
and check your string str="" once. It Should be "select * from BAsiccdtl_tbl where UserName='" + usertxt.Text +"'";

Confirm once.
[no name] 4-Jun-14 1:58am    
and also always put your code in try catch and deisplay approprite exception message whenever necessary to identify the error quickly

 
Share this answer
 
add appropriate quotes in the query
C#
String str = "select * from BasicDtl_tbl where UserName='" + usertxt.Text + "'";
 
Share this answer
 
Either your page has two form tag with runat="server" or your masterpage and contentpage both has form tag with runat="server" so remove extra form tag.. :)
 
Share this answer
 
Comments
Ashwini Thakare 4-Jun-14 2:42am    
i removed extra tag now i am getting error as "no value given for one or more required parameter"
actually basicdtl_tbl have 4 column as ID, UserName,Nationality, Post
i want to retrieve only values of Nationality and post and display it in respective textbox
Ajith K Gatty 4-Jun-14 3:02am    
if you want only Nationality, remove * and add what you want to retrieve(Column Name) based on UserName.
add try catch block always when you are working with databases. It will help you a lot in finding errors.
Ashwini Thakare 4-Jun-14 4:47am    
protected void Submitbtn_Click(object sender, EventArgs e)
{



string connection_string = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\HILProject\project4\App_Data\adminlog.mdb";
using (OleDbConnection cn = new OleDbConnection(connection_string))
{
cn.Open();


String str = "select Nationality, Post from BasicDtl_tbl where UserName=" + usertxt.Text;
OleDbCommand cmd = new OleDbCommand(str,cn);
// cmd.Connection = cn;
OleDbDataAdapter ad = new OleDbDataAdapter(cmd);
System.Data.DataSet ds = new System.Data.DataSet();
try
{
ad.Fill(ds);

Nattxt.Text = ds.Tables[0].Rows[0].ItemArray[3].ToString();
apldposttxt.Text = ds.Tables[0].Rows[0].ItemArray[4].ToString();
cn.Close();

}
catch(Exception)
{
StatusLabel.Text = "error occured";
}
}
data does not get retrieved

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900