相关文章推荐
深沉的便当  ·  GitHub | DevOps ...·  5 月前    · 
绅士的竹笋  ·  海悅聯名卡·  1 年前    · 
阳刚的烤地瓜  ·  Parsing dates in ...·  1 年前    · 
刚毅的酱牛肉  ·  java bufferedwriter ...·  1 年前    · 
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 ; // Progressbar Progressbar1 .Visible = true ; Progressbar1 .Style = ProgressBarStyle.Marquee; var period2 = cb1.SelectedValue.ToString(); var period1 = cb2.SelectedValue.ToString(); /* A variable to hold the parameters*/ // var table = await loadTable((period1, period2)); await Task.Run(() => loadTable(period1, period2)); /* back to the UI */ // datagridview1.DataSource = datatable; // datagridview1.DataSource = table; 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); // open the connection con.Open(); SqlDataAdapter adapter = new SqlDataAdapter(cmd); DataTable datatable = new DataTable(); adapter.Fill(datatable ); await Task.Run(() => adapter.Fill(datatable ));
Ok. If i use the line var table = await loadTable((period1, period2)); and set it to the DGV it underline table saying "void" can not implicitly typed local variables are allocated.

And if I use this line: datagridview1.DataSource = datatable; it states the name database does not exist in the current context.
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); // open the connection // Here open the connection async: 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.
  •