fakhravari
یک شنبه 27 شهریور 1390, 16:49 عصر
با سلام
public class AddRecord
{
public string Title;
public string Abstract;
public string Contents;
public string AddDate;
public int NewsID;
public string img;
public void AddRecord1()
{
SqlConnection connection = new SqlConnection(@"Data Source=.\sqlexpress;Initial Catalog=DatabaseCenter;Integrated Security=True") ;
SqlCommand command = new SqlCommand(
"INSERT INTO TBLNews (Title, Abstract,Contents, AddDate, img) Values (@Title, @Abstract, @Contents,@AddDate, @img)", connection);
command.Parameters.Add("@Title",SqlDbType.NVarChar ,50).Value = Title;
command.Parameters.Add("@Abstract", SqlDbType.NVarChar, 50).Value = Abstract;
command.Parameters.Add("@Contents", SqlDbType.NVarChar, 50).Value = Contents;
command.Parameters.Add("@AddDate", SqlDbType.NVarChar, 50).Value = AddDate;
command.Parameters.Add("@img", SqlDbType.NVarChar, 50).Value = img;
connection.Open();
command.ExecuteNonQuery();
}
}
اینم فراخونی عکس
protected void Button4_Click(object sender, EventArgs e)
{
string UpPath;
UpPath = Server.MapPath("pics\\");
if (!Directory.Exists(UpPath))
{
Directory.CreateDirectory(Server.MapPath("pics\\"));
}
pathImage = Server.MapPath(".") + "\\pics\\";
String[] validext = { ".jpg", ".jpeg", ".bmp", ".jpe", ".png", ".gif", ".tiff", ".tif", ".bmp" };
string ext = System.IO.Path.GetExtension(FileUpload1.PostedFile .FileName);
if (Array.IndexOf(validext, ext.ToLower()) < 0)
{
LabelError.Text = "قادر به آپلود فایل با این فرمت نیستید";
LabelError.Visible = true;
return;
}
ImageFileName = System.IO.Path.GetFileName(FileUpload1.PostedFile. FileName);
while (System.IO.File.Exists(pathImage + ImageFileName))
{
ImageFileName = "1" + ImageFileName;
LabelError.Visible = false;
}
FileUpload1.PostedFile.SaveAs(pathImage + ImageFileName);
string FilePath = "pics\\" + ImageFileName;
Image1.ImageUrl = FilePath;
return;
}
تعریف متغیر عمومی
string pathImage; string ImageFileName;
دکمه ذخیره
protected void Button1_Click(object sender, EventArgs e)
{
AddRecord ct = new AddRecord();
ct.Title = TextBox1.Text;
ct.AddDate = TextBox5.Text;
ct.Abstract = TextBox4.Text;
ct.Contents = CKEditor.Text.ToString();
ct.img = ImageFileName;
ct.AddRecord1();
}
بعد از ثبت eror میده اشکال از کجاست؟
public class AddRecord
{
public string Title;
public string Abstract;
public string Contents;
public string AddDate;
public int NewsID;
public string img;
public void AddRecord1()
{
SqlConnection connection = new SqlConnection(@"Data Source=.\sqlexpress;Initial Catalog=DatabaseCenter;Integrated Security=True") ;
SqlCommand command = new SqlCommand(
"INSERT INTO TBLNews (Title, Abstract,Contents, AddDate, img) Values (@Title, @Abstract, @Contents,@AddDate, @img)", connection);
command.Parameters.Add("@Title",SqlDbType.NVarChar ,50).Value = Title;
command.Parameters.Add("@Abstract", SqlDbType.NVarChar, 50).Value = Abstract;
command.Parameters.Add("@Contents", SqlDbType.NVarChar, 50).Value = Contents;
command.Parameters.Add("@AddDate", SqlDbType.NVarChar, 50).Value = AddDate;
command.Parameters.Add("@img", SqlDbType.NVarChar, 50).Value = img;
connection.Open();
command.ExecuteNonQuery();
}
}
اینم فراخونی عکس
protected void Button4_Click(object sender, EventArgs e)
{
string UpPath;
UpPath = Server.MapPath("pics\\");
if (!Directory.Exists(UpPath))
{
Directory.CreateDirectory(Server.MapPath("pics\\"));
}
pathImage = Server.MapPath(".") + "\\pics\\";
String[] validext = { ".jpg", ".jpeg", ".bmp", ".jpe", ".png", ".gif", ".tiff", ".tif", ".bmp" };
string ext = System.IO.Path.GetExtension(FileUpload1.PostedFile .FileName);
if (Array.IndexOf(validext, ext.ToLower()) < 0)
{
LabelError.Text = "قادر به آپلود فایل با این فرمت نیستید";
LabelError.Visible = true;
return;
}
ImageFileName = System.IO.Path.GetFileName(FileUpload1.PostedFile. FileName);
while (System.IO.File.Exists(pathImage + ImageFileName))
{
ImageFileName = "1" + ImageFileName;
LabelError.Visible = false;
}
FileUpload1.PostedFile.SaveAs(pathImage + ImageFileName);
string FilePath = "pics\\" + ImageFileName;
Image1.ImageUrl = FilePath;
return;
}
تعریف متغیر عمومی
string pathImage; string ImageFileName;
دکمه ذخیره
protected void Button1_Click(object sender, EventArgs e)
{
AddRecord ct = new AddRecord();
ct.Title = TextBox1.Text;
ct.AddDate = TextBox5.Text;
ct.Abstract = TextBox4.Text;
ct.Contents = CKEditor.Text.ToString();
ct.img = ImageFileName;
ct.AddRecord1();
}
بعد از ثبت eror میده اشکال از کجاست؟