Нужна помощь в C# date time insert and update
*/ con.Open(); cmd = new SqlCommand("INSERT INTO student_details (name, father, mother, surname, phone, email, grno, course, rollno, yearofjoin,state,blood,address,pic) VALUES ('" + name.Text + "','" + father.Text + "','" + mother.Text + "','" + surname.Text + "','" + phone.Text + "','" + email.Text + "','" + grno.Text + "','" + course.Text + "','" + rollno.Text + "','" + Convert.ToDateTime(yearofjoin.Text) + "','" + comboBox1sem.Text + "','" + comboBox1blood.Text + "','" + address.Text + "',@pic)", con); MemoryStream stream = new MemoryStream(); pictureBox1.Image.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg); byte[] pic = stream.ToArray(); cmd.Parameters.AddWithValue("@pic", pic); j = cmd.ExecuteNonQuery();
код обновления
cmd = new SqlCommand(@"UPDATE student_details SET name='" + uname.Text + "',father='" + ufather.Text + "',mother='" + umother.Text + "',surname='" + usurname.Text + "',phone='" + uphone.Text + "',email='" + uemail.Text + "',course='" + ucourse.Text + "',rollno='" + urollno.Text + "',yearofjoin='" + uyearofjoin.Text + "',state='"+comboBox1usem.Text+"',blood='"+comboBox1ublood.Text+"',address='"+uaddress.Text+"',pic=@img where (grno='" + ugrno.Text + "')", con); MemoryStream stream = new MemoryStream(); pictureBox1.Image.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg); byte[] pic = stream.ToArray(); cmd.Parameters.AddWithValue("@img", pic); j = cmd.ExecuteNonQuery(); if (j > 0) { MessageBox.Show("Record Updated Successfully..."); } ClearingText(); con.Close();
Что я уже пробовал:
может ли кто-нибудь переписать код вставки и обновить код для меня
Maciej Los
Никогда не используйте такие команды, как sql, потому что они уязвимы для SqlInjection!
ZurdoDev
Нет.