need help

  • Thread starter Thread starter Mike
  • Start date Start date
M

Mike

I have an asp.net page in C# and this code does not when I point it to my
database, it works fine going against the pubs sql db but not mine

String selectCmd = "SELECT dbo.Task.emailAddress, dbo.Task.tasks,
dbo.Task.datePosted, dbo.Task.comments FROM dbo.Team INNER JOIN dbo.Task ON
dbo.Team.ID = @me";

SqlConnection myConnection = new
SqlConnection("server=servername;database=techForum;Trusted_Connection=yes")
;
SqlDataAdapter myCommand = new SqlDataAdapter(selectCmd, myConnection);

myCommand.SelectCommand.Parameters.Add(new SqlParameter("@me",
SqlDbType.NVarChar, 2));
myCommand.SelectCommand.Parameters["@me"].Value =
MySelect.SelectedItem.Value;

DataSet ds = new DataSet();
myCommand.Fill(ds, "Task");
MyDataGrid.DataSource= ds.Tables["Task"].DefaultView;
MyDataGrid.DataBind();


what it does is populate a grid depending on what the user selects in the
drop down. Note: this same exact code does work when i point to the pubs, or
nwind database, (just need to change the query.)
 
There are 2 items I can see.
1.) this is probably not it, but using Trusted Connections in an aspx
application can be problematic as the User of the app is usually a
non-trusted guest account. Is the SQL Server you are hitting a local
install in both cases?
2.) your sql statement is doing a join where the ON clause is between a
field in Task and a parameter. Shouldn't you be joining ON 2 fields, and
whereing the parameter? We would need to see the Table Defs for the 2
tables to give any better advice, I think.
 
the sql server is local, for both my db and the pubs db which the code works
with fine.
I did change my sql to thi:

String selectCmd = "SELECT dbo.Task.tasks, dbo.Task.status,
dbo.Task.datePosted, dbo.Task.comments FROM dbo.Team INNER JOIN dbo.Task ON
dbo.Team.ID = dbo.Task.ID WHERE dbo.Task.ID = @me";

where me is the selection from the drop down. I did run this query against
the sql dbs and got the correct restuts (with the where clause hard coded.)





Bob Boran said:
There are 2 items I can see.
1.) this is probably not it, but using Trusted Connections in an aspx
application can be problematic as the User of the app is usually a
non-trusted guest account. Is the SQL Server you are hitting a local
install in both cases?
2.) your sql statement is doing a join where the ON clause is between a
field in Task and a parameter. Shouldn't you be joining ON 2 fields, and
whereing the parameter? We would need to see the Table Defs for the 2
tables to give any better advice, I think.


Mike said:
I have an asp.net page in C# and this code does not when I point it to my
database, it works fine going against the pubs sql db but not mine

String selectCmd = "SELECT dbo.Task.emailAddress, dbo.Task.tasks,
dbo.Task.datePosted, dbo.Task.comments FROM dbo.Team INNER JOIN dbo.Task ON
dbo.Team.ID = @me";

SqlConnection myConnection = new
SqlConnection("server=servername;database=techForum;Trusted_Connection=yes")
;
SqlDataAdapter myCommand = new SqlDataAdapter(selectCmd, myConnection);

myCommand.SelectCommand.Parameters.Add(new SqlParameter("@me",
SqlDbType.NVarChar, 2));
myCommand.SelectCommand.Parameters["@me"].Value =
MySelect.SelectedItem.Value;

DataSet ds = new DataSet();
myCommand.Fill(ds, "Task");
MyDataGrid.DataSource= ds.Tables["Task"].DefaultView;
MyDataGrid.DataBind();


what it does is populate a grid depending on what the user selects in the
drop down. Note: this same exact code does work when i point to the
pubs,
or
nwind database, (just need to change the query.)
 
Back
Top