我需要阅读关于如何将 DevExpress 中的 gridView 导出到 SQL 表的小课程。就像值 First Name、Father Name、Last Name 到表 Employee 一样,我有很多行。如何循环到每一行并将数据发送到数据库..
提前谢谢
我试过这段代码:
string sql = @"INSERT INTO Emp (@FName, @MName,@LName, @Code, @TaxNb, @SSN, @EmploymentType, @DOB, @MarStat, @RegNum, @BadgeNum, @HireDate, @TaxSince, @HireSince, @ArEmpName, @ArFatherName, @ArLastName, ArPayUnit)";
DataTable table = new DataTable();
try
{
SqlConnection connection = new SqlConnection(@"workstation id = PC-PC; user id=sa;Password=sapassword; data source=pc-pc; persist security info=True;initial catalog=CleanPayrollTest2");
SqlCommand command = new SqlCommand(sql, connection);
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.InsertCommand = command;
connection.Open();
// for (int i =0; i< gridView3.RowCount; i++)
//{
//command.Parameters.Add(@FirstName, gridView3.GetRowCellValue(i,gridView3.Columns));
//adapter.InsertCommand.ExecuteNonQuery();
//}
SqlParameter[] MyParams = new SqlParameter[28];
MyParams[0] = new SqlParameter("@FName", SqlDbType.VarChar, 20);
MyParams[0].SourceColumn = FirstName;
command.Parameters.Add("@FName", SqlDbType.VarChar, 20);
MyParams[1] = new SqlParameter("@MName", SqlDbType.VarChar, 20);
MyParams[1].SourceColumn = FatherName;
MyParams[2] = new SqlParameter("@LName", SqlDbType.VarChar, 20);
MyParams[2].SourceColumn = LastName;