elham deljooei

elham deljooei

  • NA
  • 84
  • 73.3k

Bind Textbox to specific column of a datatable

Jan 19 2013 3:43 AM
Hi everyone
This is my code. I want to bind Id column of DataTable to TextBox but...

SqlDataAdapter adp = new SqlDataAdapter();
            adp.SelectCommand = new SqlCommand();
            adp.SelectCommand.Connection = conn;
            adp.SelectCommand.CommandText = "EvaluationPercent_Search";
            adp.SelectCommand.CommandType = CommandType.StoredProcedure;
           
            adp.SelectCommand.Parameters.AddWithValue("@epcnt_Name", txtNameEvaluation.Text);
            DataTable dtbl = new DataTable();
            conn.Open();
            adp.Fill(dtbl);
            conn.Close();
            /*txtNameEvaluation.DataBindings.Add("Text", dtbl, "epcnt_Name");// it's correct.
            txtNameEvaluation.DataBindings.Clear(); // it's correct.
            txtDarsadEvaluation.DataBindings.Add("Text", dtbl, "epcnt_Percent");   // it's correct.            
            txtDarsadEvaluation.DataBindings.Clear();// it's correct.
            txtIdEvaluation.DataBindings.Add("Text", dtbl,( "epcnt_Id")); // it's not correct.
            txtIdEvaluation.DataBindings.Clear();*/// it's not correct.
           /* foreach (DataColumn  item in dtbl.Columns)
            {
                txtIdEvaluation.Text = dtbl.Rows[0]["@id"].ToString();// it's not correct.
                txtNameEvaluation.Text = dtbl.Rows[0]["epcnt_Name"].ToString();// it's correct.
                txtDarsadEvaluation.Text = dtbl.Rows[0]["epcnt_Percent"].ToString();// it's correct.
            }*/
This is my StoreProcedure and it's correct

Use ClerksEvaluation
Go
Alter Procedure EvaluationPercent_Search

@epcnt_Name Nvarchar(50)

AS

Declare @id int;

Select @id = epcnt_Id From EvaluationPercent
Where epcnt_Name = @epcnt_Name;

select @id, epcnt_Name, epcnt_Percent From EvaluationPercent
Where @id= epcnt_Id


Answers (1)