namespace Gtec_Solution{
public partial class Main : Form {
string myconnection = "datasource=localhost;port=3306;username = root;password = 12345V";
public Main(string userName){
InitializeComponent();
load_table_1();
}
public void load_table_1(DataTable dt){
DataTable d;
Load_Table_Class ld = new Load_Table_Class();
string Query_1 = "SELECT * FROM gtec_computer.employee";
d = ld.loading_table(Query_1);
dataGridView3.DataSource = d;
}
}
}
namespace Gtec_Solution{
public class Load_Table_Class{
public DataTable loading_table(string Query){
string myconnection = "datasource=localhost;port=3306;username = root;password = 12345V";
MySqlConnection con = new MySqlConnection(myconnection);
MySqlCommand cmd = new MySqlCommand(Query, con);
con.Open();
MySqlDataAdapter mda = new MySqlDataAdapter();
mda.SelectCommand = cmd;
DataTable dt = new DataTable();
mda.Fill(dt);
BindingSource bs = new BindingSource();
bs.DataSource = dt;
mda.Update(dt);
return dt;
}
}
}
-3
A
回答
2
那麼,錯誤消息說,這一呼籲:
load_table_1();
是無效的,因爲這個方法沒有沒有PARAMS過載。但是你已經申報load_table_1
參數dt
無論如何都不會使用,所以你可以放心地將其刪除:
public void load_table_1()
{
DataTable d;
Load_Table_Class ld = new Load_Table_Class();
string Query_1 = "SELECT * FROM gtec_computer.employee";
d = ld.loading_table(Query_1);
dataGridView3.DataSource = d;
}
0
0
你需要一個DataTable
傳遞給方法load_table_1
你定義的函數爲:
public void load_table_1(DataTable dt)
{
DataTable d;
Load_Table_Class ld = new Load_Table_Class();
string Query_1 = "SELECT * FROM gtec_computer.employee";
d = ld.loading_table(Query_1);
dataGridView3.DataSource = d;
}
因此,你需要做的:
DataTable dt = new DataTable(); // Or populate it from your service
load_table_1(dt); // pass the dt object as an argument to load_table_1
或刪除DataTable
來自該方法的論點。例如:
public void load_table_1()
{
DataTable d;
Load_Table_Class ld = new Load_Table_Class();
string Query_1 = "SELECT * FROM gtec_computer.employee";
d = ld.loading_table(Query_1);
dataGridView3.DataSource = d;
}
0
在方法Main
:
load_table_1();
但在其他地方在Main
類:
public void load_table_1(DataTable dt)
您需要傳遞一個的實例至load_table_1
。
0
在這裏,您調用不帶參數的方法:
public Main(string userName)
{
InitializeComponent();
load_table_1(); //THIS LINE
}
然而,你調用的方法需要一個參數:
public void load_table_1(DataTable dt) // IN HERE
{
DataTable d;
Load_Table_Class ld = new Load_Table_Class();
string Query_1 = "SELECT * FROM gtec_computer.employee";
d = ld.loading_table(Query_1);
dataGridView3.DataSource = d;
}
第二種方法不會用參數,所以才刪除它看起來如下:
public void load_table_1() // DELETE PARAM HERE
{
DataTable d;
Load_Table_Class ld = new Load_Table_Class();
string Query_1 = "SELECT * FROM gtec_computer.employee";
d = ld.loading_table(Query_1);
dataGridView3.DataSource = d;
}
相關問題
- 1. 剃刀:沒有過載的方法'寫'需要0個參數
- 2. 沒有超載需要'0'參數[c#]
- 3. 方法'GetTouchPoint'沒有重載需要0個參數
- 4. 沒有重載方法「sqlQuery」需要0個參數 - C#錯誤
- 5. 如何解決「方法沒有超載」需要0個參數「?
- 6. 方法沒有超載,需要0個參數?
- 7. 方法'寫'沒有超載需要0個參數
- 8. 沒有超載的方法需要0個參數
- 9. 方法'Write'沒有超載需要0個參數,MVC3 Razor
- 10. 方法'DisplayOutput'沒有超載需要0個參數
- 11. 方法沒有過載'方法'有0個參數
- 12. 沒有過載的方法'寫'在MVC3 Razor格式需要0個參數,
- 13. 沒有超載的方法需要0個參數,我錯過了什麼?
- 14. 錯誤CS1501:沒有過載的方法`反向'需要'0'參數
- 15. 沒有方法「GetValue」的過載需要1個參數
- 16. 沒有過載的方法「ToString」需要1個參數
- 17. 沒有過載方法'打開'/'運行'需要'1'參數
- 18. 沒有過載的方法需要4個參數
- 19. 錯誤沒有重載方法的'添加'需要'0'參數,使用Word Interop
- 20. 如何解決「方法沒有超載,需要0個參數?」錯誤
- 21. 實例化一個類 - 沒有重載方法'主題'需要'0'參數
- 22. 沒有超載方法'conversationOutput'需要'2'參數
- 23. Monitor.Enter:沒有超載的方法需要2個參數
- 24. 方法'Given'沒有超載需要4個參數 - specflow
- 25. 方法'GetActiveInstructors'沒有超載需要2個參數
- 26. 沒有超載的方法''需要1個參數
- 27. 沒有超載的方法'距離'需要1個參數
- 28. 沒有超載的方法'TryParse'需要'1'參數
- 29. 沒有重載方法「GetKennel」需要1個參數C#
- 30. 「MVC3中沒有重載方法'LabelFor'需要2個參數」
你有好的代碼,你也有問題嗎? – CodeCaster
錯誤消息顯示IMO。 –
看起來你正在調用一個沒有參數的方法,當你定義它時需要一個參數。 –