Click here to Skip to main content
15,894,343 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi
The following command will display only one record in a form
What do all of my records to display??????????

C#
string con = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\mobile.mdf;Integrated Security=True;User Instance=True";
        SqlConnection sqlcon = new SqlConnection();
        sqlcon.ConnectionString = con;
        SqlCommand cmd = new SqlCommand();
        cmd.Connection = sqlcon;
        cmd.CommandText = "StoredProcedure1";
        cmd.CommandType = CommandType.StoredProcedure;
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet dta = new DataSet();
            da.Fill(dta);
        try
        {
            sqlcon.Open();
            FormView1.DataSource = dta;
                FormView1.DataBind();
            sqlcon.Close();
        }
        catch
        {
            //
        }


code store procedure

SQL
ALTER PROCEDURE dbo.StoredProcedure1
as
begin
select * from tproduct
end;
Posted
Comments
Rahul VB 19-Apr-14 13:45pm    
"select * from tproduct" shows all the records from tproduct table. But the thing is if it needs to display only one record then you need to add a condition. What is your requirement?

1 solution

Hello Farhad,

As per microsoft
"The FormView control is used to display a single record from a data source in a table. When using the FormView control, you specify templates to display and edit bound values. The templates contain formatting, controls, and binding expressions to create the form. The FormView control is often used in combination with a GridView control for master/detail scenarios. This section contains the following topics about the FormView control."
Reference: FormView Web Server Control [^]

Solution of your requirement please use DataList, Repeater or Gridview to show all records and click on Edit button you can use FormView to Update or selected records.
 
Share this answer
 
Comments
Farhad Mirshekar 30-Apr-14 14:48pm    
thanks for solution

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