Tuesday, March 20, 2012

ASP 2.0 sql syntax change?

I was simply trying to create a sql command using ASP 2.0 but the syntax appears to have changed. I was trying to write the following:

SqlCommand

cmdUpdateData =newSqlCommand("AddMessage", myConnection);

cmdUpdateData.CommandType = CommandType.StoredProcedure;

But, intellisence will not offer me the second 'CommandType' on the second line?? It works fine using ASP 1.1 but not here on 2.0

Can anyone please help?

Looks ok to me. Are you importing system.data and system.data.sqlclient?|||

Yes I was lacking the system.data namespace!

Many thanks,

James

|||

That all works fine now, but a little further down my code where I fill the datagrid I have another problem with the changing sysntax.

In visual studio 2003 I would use the following:

try

{

//first open the connection

myConnection.Open();

//fill data set with data from sql data adapter

myAdapter.Fill(ds);

//bind the data grid to the datasetthis.dgdShowStudents.DataSource=ds;this.dgdShowStudents.DataKeyField="StudentId";this.dgdShowStudents.DataBind();

However, using ASP2.0 intellisence does not pick up on DataKeyField. Should I be using something else? or do I have to use the wizard for filling a grid. I'd rather do it with code?

|||Is it a datagrid or a gridview?|||GridView. I assumed it would take the same code as the DataGrid|||

If you are using the gridview, I would normally bind it to a sqldatasource control instead of using code. It's a lot simplier and it handles some things very nicely for you (Sortable columns, caching, etc).

The gridview is similiar, but not the same as a datagrid. As for the datakeys, the gridview supports multiple column binding, which I don't believe the datagrid did. I believe the property you are looking for is called DataKeyNames for the gridview.

|||

Many thanks for the help,

James

No comments:

Post a Comment