-2

I know I can drag/drop an sqlDataSource object onto my webform and then get my connection string from my webconfig file and link it and done... But I don't want to do it that way. I want to do it programmatically.

as it can be done in a windows form app like so:

SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DatabaseConnectionDev"].ConnectionString);
string command = "SELECT * FROM DUMMY";
SqlDataAdapter dataAdapter = new SqlDataAdapter(command, conn);

SqlCommandBuilder commandBuilder = new SqlCommandBuilder(dataAdapter);
DataSet ds = new DataSet();
dataAdapter.Fill(ds);
dgvDelete.DataSource = ds.Tables[0];

How can I do this in a web form?

I think I have to use the sqlDataSource object and set it up that way but I don't know how.

Can someone show me?

Pragmateek
  • 13,174
  • 9
  • 74
  • 108

2 Answers2

0

if you want see the data in the GridView control you must add this:

dgvDelete.DataBind();

For more details check this question

Community
  • 1
  • 1
Tinwor
  • 7,765
  • 6
  • 35
  • 56
0

If I understand the question you can create a function to return a DataTable which contains the data your want to view (or wherever you want to put the code). Then set the GridView control's datasource to your datatable then databind.

yourGridView.DataSource = yourDataTable

yourGridView.DataBind()

Jason Sgalla
  • 176
  • 9