Suji D

Suji D

  • NA
  • 23
  • 7.5k

How to display the last five data's from Remote database ta

Jun 1 2015 5:20 AM

Hi all,

Good Day! I am using C# in Visual Studio 2008 and SQL server 2008. In this i need to display the data's from remote database and have to view in data grid view.

and my Code is Below.

for (int i = 0; i < 5; i++)
{
string frmqry = "Select fldFrom&" + i + " from tmessage_temp where fldsno=IDENT_CURRENT('tmessage_temp')";
cmd = new SqlCommand(frmqry, cn);
cmd.CommandType = CommandType.Text;
SqlDataAdapter sdr1 = new SqlDataAdapter(cmd);
DataTable dt1 = new DataTable();
sdr1.Fill(dt1);
string newfrmqry = "";
newfrmqry = cmd.ExecuteScalar().ToString();
dataGridView1.Rows[1].Cells[0].Value = "fldFrom";
dataGridView1.Rows[2].Cells[1].Value = "fldFrom";
dataGridView1.Rows[3].Cells[2].Value = "fldFrom";
dataGridView1.Rows[4].Cells[3].Value = "fldFrom";
dataGridView1.Rows[5].Cells[4].Value = "fldFrom";
dataGridView1.DataSource = dt1.DefaultView;
}

Answers (1)