Click here to Skip to main content
15,910,980 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, actually, i wrote a function on Data Access layer with the help of stored procedurę and want to call this function on comboBox1_SelectedIndexChanged and i want ot fill my textboxes with dilldataset().
C#
public DataSet Filldataset(Bussinessobject.BOEBO)
 
 {
 
objconn =  newSqlConnection(connectionstring);
 
objconn.Open();
 
objcommand = newSqlCommand("sp_filltextfromcombo", objconn);
 
objcommand.CommandType = CommandType.StoredProcedure;
 
objcommand.Parameters.AddWithValue("@name",EBO.fname);
 



SqlDataAdapterda = newSqlDataAdapter();
 
da.SelectCommand = objcommand;
 
// DataTable dt = new DataTable("tblEmployeeInfo");
 
DataSetobjdataset = newDataSet();
 
 da.Fill(objdataset);
 
return objdataset;
 
      }

i m calling Filldataset function here for fill this textboxes but i can't plz some one help me to fetch data in textboxes with the help of this filldataset()plz make me correct if i m wrong i need some code plz
C#
private void comboBox1_SelectedIndexChanged(objectsender, EventArgse)
 
{
 
Bussinessobject.BOEBO = newBussinessobject.BO();
 
comboBox1.DataSource = EBO.Filldataset(EBO).Tables[0];
 
txtEid.Text = Convert.ToInt32(EBO.Filldataset(EBO).Tables[0].Rows[0][0]).ToString();
 
txtEfname.Text = Convert.ToString(EBO.Filldataset(EBO).Tables[0].Rows[0][1]);
 
txtElname.Text = Convert.ToString(EBO.Filldataset(EBO).Tables[0].Rows[0][2]);
 
}
Posted
Updated 8-Oct-13 8:21am
v2

1 solution

Hey there,

Change the SelectedIndexChanged event to this:
C#
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            Bussinessobject.BOEBO = newBussinessobject.BO();
            DataSet ds = EBO.Filldataset(EBO);

            if (ds != null && ds.Tables.Count > 0)
            {
                DataTable dt = EBO.Filldataset(EBO).Tables[0];
                if (dt != null && dt.Rows.Count > 0)
                {
                    txtEid.Text = dt.Rows[0][0].ToString();
                    txtEfname.Text = dt.Rows[0][1].ToString();
                    txtElname.Text = dt.Rows[0][2].ToString();
                }
            }
        }


if you know the specific Column names you can specify them like this:
C#
dt.Rows[0]["YourColumnName"].ToString()


Let me know if helps.

Azee...
 
Share this answer
 
v2

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