سلام
با این روش یک eror رخ می ده
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
public class AddRecord
{
public string Title;
public string Abstract;
public string Contents;
public string AddDate;
public int NewsID;
public string photoFilePath;
public string img;
public void AddRecord1()
{
byte[] photo = GetPhoto(photoFilePath);
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 , 40).Value = Title;
command.Parameters.Add("@Abstract",SqlDbType.NVarC har, 40).Value = Abstract;
command.Parameters.Add("@Contents",SqlDbType.NVarC har, 40).Value = Contents;
command.Parameters.Add("@AddDate",SqlDbType.NVarCh ar).Value = AddDate;
command.Parameters.Add("@img",SqlDbType.Image, photo.Length).Value = photo;
connection.Open();
command.ExecuteNonQuery();
}
public static byte[] GetPhoto(string filePath)
{
FileStream stream = new FileStream(filePath, FileMode.Open, FileAccess.Read);
BinaryReader reader = new BinaryReader(stream);
byte[] photo = reader.ReadBytes((int)stream.Length);
reader.Close();
stream.Close();
return photo;
}
}
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 = FileUpload1.FileName;
ct.AddRecord1();
}