I've got two questions basically. I have been searching quite a bit. But I mainly find console applications that are so basic I understand them regarding SQL.
However -- I take user input from my view class and send It with a method to a connect class. I want the connect class to handle all the work with SQL. Now I have a working connection and I write a correct SQL statement. How do I return it to the view class and what would you recommend like a ListBox.
When we did this in java we got a resultset and translated it so it would fit in an jtable. I wonder how I can solve this in Visual Studio.
public void askSQL (string sqlQuestion)
{
SqlCommand cmd = new SqlCommand();
cmd.CommandText = sqlQuestion;
cmd.Connection = connector;
try
{
rdr = cmd.ExecuteReader();
while (rdr.Read())
{
MessageBox.Show("Du läser in data");
}
}
catch (Exception e)
{
MessageBox.Show("Fel vid anslutningen!" + e);
}
}
I currently have no problems with the code. The connection is working and I recieve multiple answers "Du läser in data" since there are multiple columns and rows in my table.
SqlDataReaderobject to the caller or process the data in the method itself. It depends on what you need your method to do.