Respondida specific column value not displayed

  • martes, 14 de agosto de 2012 7:54
     
     

    Dear all,

    I am trying to display specific column of database row by row.but problem arise that in a datagridview, the total number of rows is displayed,not the column value.i think i am not using the right code.

    please help me.that is a code for display the specific column to a specific datagridview column-

      
               foreach (DataGridViewRow dr in dataGridView1.Rows)
               {
                   con.Close();
                   con.Open();
                
                   DataGridViewTextBoxCell tc = dr.Cells[0] as DataGridViewTextBoxCell;
                 
                
                    

                       string query = @"select quantity from indent_items where indent_no='" + textBox1.Text + "'"; //query
                     
                       cmd = new SqlCommand(query, con);
                       SqlDataAdapter adapter = new SqlDataAdapter(cmd);
                       DataTable dt = new DataTable();
                       adapter.Fill(dt);
                       int n = dataGridView1.Rows.Count;
                       if (dr.Index != n-1)
                           dr.Cells["QtyIndent"].Value = adapter.Fill(dt).ToString();
                           
                       else
                       {
                           dr.Cells["QtyIndent"].Value = "";
                       }


                  
            
                 
                   con.Close();
               }

    or can anybody tell me, how can i display the specific column values of a database table in a datagridview specific column.

    Please help me.

    Regards

    Jitendra Gautam


    • Editado Jitendra Gautam martes, 14 de agosto de 2012 10:27
    • Cambiado CoolDadTxMVP martes, 14 de agosto de 2012 14:08 Winforms related (From:Visual C# General)
    •  

Todas las respuestas

  • martes, 14 de agosto de 2012 8:08
     
      Tiene código

    Hi,

    If u want to get the column value, plz do this——

    dr.Cells["QtyIndent"].Value = dt.Columns[0-based index].ColumnName;
    

    下载MSDN桌面工具(Vista,Win7)
    我的博客园
    慈善点击,点击此处

  • martes, 14 de agosto de 2012 9:07
     
      Tiene código
    dr.Cells["QtyIndent"].Value = dt.Columns[0-based index].ColumnName;

    this code give me the column name and i want to display the column values.

    Regards

    Jitendra Gautam


  • miércoles, 15 de agosto de 2012 1:08
     
     

    >>this code give me the column name and i want to display the column values.

    Well……:

    dr.Cells["QtyIndent"].Value = dt.Rows[0-based index][0-based index of column].ToString();


    下载MSDN桌面工具(Vista,Win7)
    我的博客园
    慈善点击,点击此处

  • jueves, 16 de agosto de 2012 5:56
     
     

    This is not helpful for me.

    Regards

    Jitendra Gautam

  • jueves, 16 de agosto de 2012 5:58
     
     

    This is not helpful for me.

    Regards

    Jitendra Gautam


    why?Can u tell us what u really want?

    下载MSDN桌面工具(Vista,Win7)
    我的博客园
    慈善点击,点击此处

  • jueves, 16 de agosto de 2012 6:37
     
     

    I am trying to pick one column from one table and another column from second table and then trying to merge them with the one more table and then want to show in datagridview.for this i was also tried the view concept but when the rows are more then once then it will shows the double number of rows.So i am trying to do this by coding.

    Regards

    Jitendra Gautam

  • jueves, 16 de agosto de 2012 6:40
     
     

    I am trying to pick one column from one table and another column from second table and then trying to merge them with the one more table and then want to show in datagridview.for this i was also tried the view concept but when the rows are more then once then it will shows the double number of rows.So i am trying to do this by coding.

    Regards

    Jitendra Gautam

    I don't understand……:(

    Can u show ur result in screenshot?

  • jueves, 16 de agosto de 2012 6:53
     
     

    After unit column,first qty column is comes from the one table and the second qty column is comes from the other table.when i am choosing the selected value from combobox, then this datagridview is appeared.and according to selected value the qty1 and qty2 is appeared.

    I hope it will clear some picture.

    Regards

    Jitendra Gautam

  • viernes, 17 de agosto de 2012 10:15
     
     Respondida Tiene código

    Hi,

    U should put two comboboxes on the winform, and when you choose several values from them, and click the button the result comes. And in the button's click u can see this——

    using(SqlDataAdapter adapter = new SqlDataAdapter("select * from xxx inner join yyy on xxx.Id=yyy.Id where field1=@field1 and field2=@field2","Your connection string here"))
    {
       adapter.SelectCommand.AddWithValue("@field1",value1);
       adapter.SelectCommand.AddWithValue("@field2",value2);
    
       DataTable dt = new DataTable();
       adapter.Fill(dt);
    
       dataGridView1.DataSource = dt;
    }

    Not test yet but offer ur ideas……Hope this helps XD


    下载MSDN桌面工具(Vista,Win7)
    我的博客园
    慈善点击,点击此处