我有這樣的方法,其中有一些數據插入到我的數據庫從另一個類C#調用方法
public Zakaznik_Mapper()
{
public bool Insert(int ID_zakaznik, String Name, String LastName, String Login, String Password, int Number, String Email, String Adress)
{
try
{
conn.Open();
tran = conn.BeginTransaction(System.Data.IsolationLevel.Serializable);
SqlCommand insertCommand = new SqlCommand("INSERT INTO Zakaznik VALUES (@ID_zakaznik, @Name, @LastName, @Login, @Password, @Number, @Email, @Adress);", conn, tran);
insertCommand.Parameters.Add(new SqlParameter("@ID_zakaznik", SqlDbType.Int) { Value = ID_zakaznik });
insertCommand.Parameters.Add(new SqlParameter("@Name", SqlDbType.VarChar) { Value = Name });
insertCommand.Parameters.Add(new SqlParameter("@LastName", SqlDbType.VarChar) { Value = LastName });
insertCommand.Parameters.Add(new SqlParameter("@Login", SqlDbType.VarChar) { Value = Login });
insertCommand.Parameters.Add(new SqlParameter("@Password", SqlDbType.VarChar) { Value = Password });
insertCommand.Parameters.Add(new SqlParameter("@Number", SqlDbType.Int) { Value = Number });
insertCommand.Parameters.Add(new SqlParameter("@Email", SqlDbType.VarChar) { Value = Email });
insertCommand.Parameters.Add(new SqlParameter("@Adress", SqlDbType.VarChar) { Value = Adress });
insertCommand.ExecuteNonQuery();
tran.Commit();
conn.Close();
return true;
}
catch (SqlException e)
{
tran.Rollback();
conn.Close();
Console.WriteLine(e);
return false;
}
}
,我想打電話從UlozZakaznik()方法插入,但我得到的錯誤類型「不過載的方法'插入'需要0個參數「如果有人可以幫助它,我會很開心:)
public void UlozZakaznik()
{
DataTable data_zakaznik = new DataTable("Zakazka");
data_zakaznik.Columns.Add("ID_Zakaznik");
data_zakaznik.Columns.Add("Name");
data_zakaznik.Columns.Add("Lastname");
data_zakaznik.Columns.Add("Login");
data_zakaznik.Columns.Add("Password");
data_zakaznik.Columns.Add("Number");
data_zakaznik.Columns.Add("Email");
data_zakaznik.Columns.Add("Adress");
Zakaznik_Mapper zakaznik = new Zakaznik_Mapper();
Zakaznik zakaznik1 = new Zakaznik();
zakaznik1.ID_zakaznik = Convert.ToInt32(dataGridView1.Rows[dataGridView1.RowCount - 2].Cells[0].Value);
zakaznik1.Name = Convert.ToString(dataGridView1.Rows[dataGridView1.RowCount - 2].Cells[1].Value);
zakaznik1.LastName = Convert.ToString(dataGridView1.Rows[dataGridView1.RowCount - 2].Cells[2].Value);
zakaznik1.Login = Convert.ToString(dataGridView1.Rows[dataGridView1.RowCount - 2].Cells[3].Value);
zakaznik1.Password = Convert.ToString(dataGridView1.Rows[dataGridView1.RowCount - 2].Cells[4].Value);
zakaznik1.Number = Convert.ToInt32(dataGridView1.Rows[dataGridView1.RowCount - 2].Cells[5].Value);
zakaznik1.Email = Convert.ToString(dataGridView1.Rows[dataGridView1.RowCount - 2].Cells[6].Value);
zakaznik1.Adress = Convert.ToString(dataGridView1.Rows[dataGridView1.RowCount - 2].Cells[7].Value);
if (dataGridView1.Rows[dataGridView1.RowCount - 2].Cells[0].Value != null
&& dataGridView1.Rows[dataGridView1.RowCount - 2].Cells[1].Value != null
&& dataGridView1.Rows[dataGridView1.RowCount - 2].Cells[2].Value != null
&& dataGridView1.Rows[dataGridView1.RowCount - 2].Cells[3].Value != null
&& dataGridView1.Rows[dataGridView1.RowCount - 2].Cells[4].Value != null
&& dataGridView1.Rows[dataGridView1.RowCount - 2].Cells[5].Value != null
&& dataGridView1.Rows[dataGridView1.RowCount - 2].Cells[6].Value != null
&& dataGridView1.Rows[dataGridView1.RowCount - 2].Cells[7].Value != null
)
{
data_zakaznik.Rows.Add(zakaznik1.ID_zakaznik, zakaznik1.Name, zakaznik1.LastName, zakaznik1.Login, zakaznik1.Password, zakaznik1.Number, zakaznik1.Email, zakaznik1.Adress);
zakaznik.Insert();//problem is here "Error type: No overload for method 'Insert' takes 0 arguments"
}
}
錯誤更換
告訴你的問題是什麼;存在用於插入件的唯一方法簽名是'公共BOOL插入(INT ID_zakaznik,字符串.....其他參數)'要麼提供參數,定義一個插入件,它沒有參數,或提供默認值。 – Chris