Jump to content

C# Form and Webservice


TotalWhat

Recommended Posts

Hey all!

 

Not sure if I put this one in the right subforum but here it goes.

 

So I have a Form application that has a button that shows the content of a SQL database.

 

So I have the sql code "select * from blabla" in my DAL. I then made a Webservice with a Webmethod for that method in the DAL. I then used "Add reference" in my Forms application to accsess the method in the DAL via the Webservice. The problem is that my method that contains the sql code returns a DataTable of the content in the database. And I guess the xml code in the webservice can't handle that format cause it crashes. Something about it being unable to generate the xml code.

 

So If I want to return the content of a table in my MSSQL database and then present it in a datagridview in a forms application, what do I need to do? I have to use a WebService in between, thats just how the assignement looks like.

 

Thank you for your reply, I do understand that the text might be somewhat hard to understand.

Link to comment
Share on other sites

//GUI

private void TestButton_Click(object sender, EventArgs e) { dataGridView1.DataSource = controller.TestMethod(); }

 

//Controller

public DataTable TestMethod() { ERPService.LU_ERPWebServiceSoapClient client = new ERPService.LU_ERPWebServiceSoapClient(); DataTable dataTable = client.TestMethod(); return dataTable; }

//Webservice

[WebMethod] public DataTable TestMethod() { DAL dal = new DAL(); DataTable dataTable = dal.TestMethod(); return dataTable; }

//DAL

public DataTable TestMethod() { command.Connection = OpenConnection(); try { command.CommandText = "select * from CRONUSSverigeAB$Employee"; SqlDataAdapter dataAdapter = new SqlDataAdapter(command); dataAdapter.Fill(dataTable); return dataTable; } catch (SqlException) { throw new DatabaseException("An error has occured. Please contact support."); } finally { command.Connection.Close(); } }

 

Maybe this will make it more understandable!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...