update()
메서드에 문제가 있습니다. 아이디어는 사용자가 조리법 이름, 재료, 지침을 제공 한 다음 Filestream을 사용하여 이미지를 선택한다는 것입니다.테이블에 데이터를 삽입하는 구문이 잘못되었습니다.
가 있습니다 : 사용자가 클릭이 일이 내가 텍스트 상자의 내용을 언급하는 오류를 얻고 서 그러나로, update 메소드를 호출합니다 '레시피 추가'를 한 번
갱신() 메소드 코드 : 나는 조리법 쿼리에 삽입하여 잘못 됐을 또는 코드의이 부분에 대한 대안 접근 방식을 제시 한 곳
private void updatedata()
{
// filesteam object to read the image
// full length of image to a byte array
try
{
// try to see if the image has a valid path
if (imagename != "")
{
FileStream fs;
fs = new FileStream(@imagename, FileMode.Open, FileAccess.Read);
// a byte array to read the image
byte[] picbyte = new byte[fs.Length];
fs.Read(picbyte, 0, System.Convert.ToInt32(fs.Length));
fs.Close();
//open the database using odp.net and insert the lines
string connstr = @"Server=mypcname\SQLEXPRESS;Database=RecipeOrganiser;Trusted_Connection=True";
SqlConnection conn = new SqlConnection(connstr);
conn.Open();
string query;
query = "insert into Recipes(RecipeName,RecipeImage,RecipeIngredients,RecipeInstructions) values (" + textBox1.Text + "," + " @pic" + "," + textBox2.Text + "," + textBox3.Text + ")";
SqlParameter picparameter = new SqlParameter();
picparameter.SqlDbType = SqlDbType.Image;
picparameter.ParameterName = "pic";
picparameter.Value = picbyte;
SqlCommand cmd = new SqlCommand(query, conn);
cmd.Parameters.Add(picparameter);
cmd.ExecuteNonQuery();
MessageBox.Show("Image successfully saved");
cmd.Dispose();
conn.Close();
conn.Dispose();
Connection();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
사람이 볼 수 있을까요?
는 표준화 된 디자인이 아닌 – ffffff01
이 또한 하나의 컬럼에 모든 RecipeIngredients 우는 .. 매개 변수화 쿼리를 사용하십시오 당신은'using' 블록을 사용한다. –
텍스트 값을 인용하지 않습니다. 각 값의 앞뒤에 작은 따옴표 (')를 넣으십시오. –