PDA

View Full Version : مشکل این کد چیست



mohsen200162
دوشنبه 04 بهمن 1389, 20:07 عصر
سلام من این برنامه را که نوشتم ایراد می گیره می شه راهنمایی کنید


privatevoid UpdatePerson(int dellid )
{
SqlConnection cnn = newSqlConnection();
cnn.ConnectionString = WebConfigurationManager.ConnectionStrings["mysql"].ConnectionString;
SqlCommand cmd = newSqlCommand();
cmd.Connection = cnn;
string MyCommandText = string.Format("Update lighting Set Object = N'{0}' ,Title = {1} where id={2}", textfull.Text, texttitel.Text, dellid);
cmd.CommandText = MyCommandText;
try
{
cnn.Open();
cmd.ExecuteNonQuery();
Label6.Text = " ";
}
catch (SqlException ex)
{
Trace.Warn(ex.Message);
Label6.Text = " . ";
}
catch (Exception ex)
{
Trace.Write(ex.Message);
Label6.Text = " ! .";
}
finally
{
cnn.Close();
}
}

این خطا رو می ده

Incorrect syntax near 'دستگاه'.

Rejnev
دوشنبه 04 بهمن 1389, 20:46 عصر
نوع title چيه؟ اگه رشته ايه بايد مقدار جلوي مساوي رو مثل object داخل تك كوتيشن بذاريد.
ميشه بگيد مقدار connection string مربوط به mysql چيه؟

mohsen200162
سه شنبه 05 بهمن 1389, 02:57 صبح
<add name="mysql" connectionString=" Data Source=.\SQLEXPRESS;AttachDbFilename=D:\diaco1\App _Data\Database.mdf;Integrated Security=True;User Instance=True" />

, نوع title هم رشته می باشد

Rejnev
سه شنبه 05 بهمن 1389, 10:33 صبح
string MyCommandText = string.Format("Update lighting Set Object = N'{0}' ,Title = '{1}' where id={2}", textfull.Text, texttitel.Text, dellid);