Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 urgent

Author  Topic 

zez0
Starting Member

24 Posts

Posted - 2008-08-04 : 07:51:59
hi for all

i'm tray to insert an image to database but there is some probelm


public bool SaveNews(string Title, string NewsDate, string Notes, string Time, string DateUpdate, byte[] image)
{
bool Test;
try
{
Conn = new OleDbConnection(connectionString);
query = "insert into News(NEWS_TITLE,NEWS_DATE,NEWS_DETAILS,NEWS_TIME,NEWS_DATE_UPDATE,IMAGE_PATH ) values ('" + Title + "','" + NewsDate + "','" + Notes + "','" + Time + "','" + DateUpdate + "'," + " @BlobParameter )";
if (Conn.State != ConnectionState.Open)
Conn.Open();

cmd = new OleDbCommand(query, Conn);

cmd.Parameters.Add(image);
int RES = cmd.ExecuteNonQuery();
if (RES < 0)
Test = false;
else
Test = true;
return Test;
}
catch (Exception Ex)
{
string message = Ex.Message;

return false;
}
finally
{
if (Conn.State != ConnectionState.Closed)
Conn.Close();
}
}

and i call it by this

private void button2_Click(object sender, EventArgs e)
{
if (imagename != "")
{

FileStream fls;

fls = new FileStream(@imagename, FileMode.Open, FileAccess.Read);

//a byte array to read the image

byte[] blob = new byte[fls.Length];

fls.Read(blob, 0, System.Convert.ToInt32(fls.Length));

fls.Close();

bool Result = SaveNews("first", "second", "thered", "forth", "fiveth", blob);

}


}


and this exeptions appear

Ex = {"The OleDbParameterCollection only accepts non-null OleDbParameter type objects, not Byte[] objects."}

can any one help me ???

zezo

zez0
Starting Member

24 Posts

Posted - 2008-08-04 : 10:55:21
thanks for all i found the solutins

zezo
Go to Top of Page
   

- Advertisement -