0

How to access database from a web service in ASP.NET? i have a [webmethod] in WebServices class and this is not calling in code file:

[WebMethod]
public DataSet Populate(string con, string sql)
{
    DataSet DS = new DataSet();
    SqlConnection conn = new SqlConnection(con);
    SqlDataAdapter DA = new SqlDataAdapter(con, sql);
    DA.Fill(DS);
    Return DS;
}
5
  • Puting Database access directly in Webmethod ? Please first create a Data Access Layer and use it. Commented Sep 3, 2012 at 10:36
  • have you get any error ? Commented Sep 3, 2012 at 10:50
  • 1
    @Massanu infact he can put database access perfectly in webmethod Commented Sep 3, 2012 at 11:29
  • 1
    @mekici I dont say it will not work, I just say that its really bad practice to put database access directly in WebMethod Commented Sep 3, 2012 at 11:59
  • @Massanu question was not about best practice Commented Sep 3, 2012 at 12:36

1 Answer 1

1

Check you sql cmd is not blank. and write as
SqlDataAdapter DA = new SqlDataAdapter(sql,con);

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

Comments

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.