08-07-19, 09:44 AM
(07-07-19, 02:35 PM)ابراهيم ايبو كتب :شكرا لهتممك استاذ ابرهيمالسلام عليكم اخي الكريمهذا تحويل الكود من VB الى Cشاربكود :
using System.Data;
using System.Data.SqlClient;
public class Form1
{
private SqlConnection conn = new SqlConnection("Data Source=.\\SQLEXPRESS;Initial Catalog=Data_Company;Integrated Security=True");
private DataSet ds = new DataSet();
private DataView dv;
private SqlDataAdapter da = new SqlDataAdapter();
private SqlCommand cmd = new SqlCommand();
private string sql;
private void Button1_Click(object sender, System.EventArgs e)
{
foreach (DataGridViewRow row in DGV_Schol.Rows)
{
if (row.Cells[0].Value == "")
{
sql = "insert into T_Schol(Schol_ID,Emp_ID,School_ID,Schol_Start,Schol_User,Schol_Date)values (@Schol_ID,@Emp_ID,@School_ID,@Schol_Start,@Schol_User,@Schol_Date)";
}
else
{
sql = "update T_Schol set Emp_ID=@Emp_ID,School_ID=@School_ID,Schol_Start=@Schol_Start,Schol_User=@Schol_User,Schol_Date=@Schol_Date where Schol_ID=@Schol_ID ";
}
cmd.Parameters.AddWithValue("@Emp_ID", row.Cells[1].Value).DbType = DbType.String;
cmd.Parameters.AddWithValue("@School_ID", row.Cells[1].Value).DbType = DbType.String;
cmd.Parameters.AddWithValue("@Schol_Start", row.Cells[1].Value).DbType = DbType.String;
cmd.Parameters.AddWithValue("@Schol_User", this.textBox1.Text.ToString());
cmd.Parameters.AddWithValue("@Schol_Date", DateTime.Today.ToString("yyyy/MM/dd").ToString());
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
}
}
}
وهذا السطر الاخركود :
GV(DGV_Schol, "select T_Schol.School_ID,School_Nam,Emp_ID,Schol_Start,Schol_User,Schol_Date from T_Schol,T_School where T_Schol.School_ID=T_School.School_ID and Emp_ID=" + textBox1.Text + "");
طبقت الكود ويعطي خطأ لو ممكن تنفذ لكود على الملف المرفق
وجزك الله كل خير
