I am have a litle problems firing my datagridview using the async / await method.
Button click event:
private
async
void
button2_Click(
object
sender, EventArgs e)
datagridview1.Visible =
true
;
Progressbar1 .Visible =
true
;
Progressbar1 .Style = ProgressBarStyle.Marquee;
var
period2 = cb1.SelectedValue.ToString();
var
period1 = cb2.SelectedValue.ToString();
await
Task.Run(() => loadTable(period1, period2));
Progressbar1 .Visible =
false
;
I haved tried fetching the DGV by using the using the two // datagridview.DataSource line without success.
My Task method:
private
async
Task Zugänge(
string
period1,
string
period2)
string
C = ConfigurationManager.ConnectionStrings[
"
123"
].ConnectionString;
using
(
var
con =
new
SqlConnection(C))
using
(
var
cmd =
new
SqlCommand())
cmd.Connection = con;
cmd.CommandText = (
"
[dbo].[spInfo]"
);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue(
"
@Periode2"
, period2);
cmd.Parameters.AddWithValue(
"
@Periode1"
, period1);
con.Open();
SqlDataAdapter adapter =
new
SqlDataAdapter(cmd);
DataTable datatable =
new
DataTable();
adapter.Fill(datatable );
await
Task.Run(() => adapter.Fill(datatable ));
string
C = ConfigurationManager.ConnectionStrings[
"
123"
].ConnectionString;
using
(
var
con =
new
SqlConnection(C))
using
(
var
cmd =
new
SqlCommand())
cmd.Connection = con;
cmd.CommandText = (
"
[dbo].[spInfo]"
);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue(
"
@Periode2"
, period2);
cmd.Parameters.AddWithValue(
"
@Periode1"
, period1);
await
con.OpenAsync();
SqlDataAdapter adapter =
new
SqlDataAdapter(cmd);
DataTable datatable =
new
DataTable();
adapter.Fill(datatable );
await
Task.Run(() => adapter.Fill(datatable ));
return
dt;
Read the question carefully.
Understand that English isn't everyone's first language so be lenient of bad
spelling and grammar.
If a question is poorly phrased then either ask for clarification, ignore it, or
edit the question
and fix the problem. Insults are not welcome.
Don't tell someone to read the manual. Chances are they have and don't get it.
Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
And if I use this line: datagridview1.DataSource = datatable; it states the name database does not exist in the current context.