2

i am extreamly stuck from morning can someone help me i have a sql data adaptor which is not returning any values . In the same page in the top i have a SQldataadaptor which works fine . I do not know what to do . The query is working fine in the Server. I am using vs10 and sqlserver 2008 ..

I have also tried by removing the parameters it is still not working '. Always my rowcount is zero

here is my code

       doc = dr["DrName"].ToString();
           sql1 = "select w.Day, w.Start,[End] from WeeklyScheduleDays w where w.Start is not null and w.Day = @day1 and  WeeklyScheduleID = (select WeeklyScheduleID from DoctorsBusinessHours db inner join drmast m  on m.DoctorId = db.DcotorID where m.DrName = '@drname2') order by Start ";


           SqlCommand m1 = new SqlCommand(sql1,myConnection);
           m1.Parameters.AddWithValue("@day1", i);
            m1.Parameters.AddWithValue("@drname2", doc);

             SqlDataAdapter ad = new SqlDataAdapter(m1);
            DataTable t1 = new DataTable();
             ad.Fill(t1);


           rowcount = t1.Rows.Count;

Thanks in advance

1
  • NO DANGER: No SQL injection! ;-) (I had to +1, because it is so rare!) Commented Mar 19, 2013 at 14:32

1 Answer 1

1

Replace where m.DrName = '@drname2' with where m.DrName = @drname2

Sign up to request clarification or add additional context in comments.

6 Comments

sql1 is just a string and i has a integer value stored in it
The query does return a set of values in server
@user2177370: Does it work if you hardcode the values into the query(just for testing purposes)? What sql query does work in ssms?
So the same sql query that does work in ssms does not work in ADO.NET? That's impossible, there must be a difference. But we don't have the second sight ;)
select w.Day as day, w.Start as start,[End] as e2 from WeeklyScheduleDays w where w.Start is not null and w.Day = 2 and WeeklyScheduleID = (select WeeklyScheduleID from DoctorsBusinessHours db inner join drmast m on m.DoctorId = db.DcotorID where m.DrName = 'nurses') order by Start is my SQL Statement
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.