faramarz_s
پنج شنبه 03 مهر 1382, 11:29 صبح
public bool bindToDatGrid(int x)
{
try
{
SqlConnection cnn = new
SqlConnection("server=(local);uid=sa;pwd=yaali;database=MDB" );
SqlDataAdapter sqlDataAdapter1 = new
SqlDataAdapter("select * from tblPictures",cnn);
sqlDataAdapter1.SelectCommand.CommandText = "Select * From tblPictures id = "
+ Convert.ToString(x);
DataSet ds = new DataSet();
sqlDataAdapter1.Fill(ds, "tblPictures");
DataGrid1.DataSource = ds.Tables["tblPictures"].DefaultView;
DataGrid1.DataBind();
if (ds.Tables[0].Rows.Count == 0)
return false;
// populate the hidden answers:
// now we need to get the picture from the DataRow
// and assign it to a byte array
byte[] MyData =null;
MyData = (byte[])ds.Tables[0].Rows[0]["Image"];
int ArraySize = new int();
ArraySize = MyData.GetUpperBound(0);
// Create a Filestream for writing the byte array to a gif file (the original format in this case)
FileStream fs = new FileStream("web.gif", FileMode.OpenOrCreate, FileAccess.Write);
// Write the stream of data that we read in from the database to the filestream and close it.
// This will create the file tmp.gif, which we can use to display in the picturebox
fs.Write(MyData, 0,ArraySize+1); // don't ask me why, but I had to add 1 here for this to work
fs.Close();
// Assign the temporary gif file to the picture box
//pictureBox1.Image = new Bitmap("web.gif");
Image1.ImageUrl= new Bitmap("Web.Gif").ToString();
return true;
}
catch (Exception ex)
{
Response.Write(ex.Message.ToString());
}
}
کد فوق جهت خواندن داده از بانک اسکیوئل برای نمایش عکس است:
d:\inetpub\wwwroot\InsertImage\WebForm1.aspx.cs(55 ): 'InsertImage.WebForm1.bindToDatGrid(int)': not all code paths return a value
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[tblPictures]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[tblPictures]
GO
CREATE TABLE [dbo].[tblPictures] (
[id] [int] NOT NULL ,
[Image] [varbinary] (50) NULL
) ON [PRIMARY]
GO
{
try
{
SqlConnection cnn = new
SqlConnection("server=(local);uid=sa;pwd=yaali;database=MDB" );
SqlDataAdapter sqlDataAdapter1 = new
SqlDataAdapter("select * from tblPictures",cnn);
sqlDataAdapter1.SelectCommand.CommandText = "Select * From tblPictures id = "
+ Convert.ToString(x);
DataSet ds = new DataSet();
sqlDataAdapter1.Fill(ds, "tblPictures");
DataGrid1.DataSource = ds.Tables["tblPictures"].DefaultView;
DataGrid1.DataBind();
if (ds.Tables[0].Rows.Count == 0)
return false;
// populate the hidden answers:
// now we need to get the picture from the DataRow
// and assign it to a byte array
byte[] MyData =null;
MyData = (byte[])ds.Tables[0].Rows[0]["Image"];
int ArraySize = new int();
ArraySize = MyData.GetUpperBound(0);
// Create a Filestream for writing the byte array to a gif file (the original format in this case)
FileStream fs = new FileStream("web.gif", FileMode.OpenOrCreate, FileAccess.Write);
// Write the stream of data that we read in from the database to the filestream and close it.
// This will create the file tmp.gif, which we can use to display in the picturebox
fs.Write(MyData, 0,ArraySize+1); // don't ask me why, but I had to add 1 here for this to work
fs.Close();
// Assign the temporary gif file to the picture box
//pictureBox1.Image = new Bitmap("web.gif");
Image1.ImageUrl= new Bitmap("Web.Gif").ToString();
return true;
}
catch (Exception ex)
{
Response.Write(ex.Message.ToString());
}
}
کد فوق جهت خواندن داده از بانک اسکیوئل برای نمایش عکس است:
d:\inetpub\wwwroot\InsertImage\WebForm1.aspx.cs(55 ): 'InsertImage.WebForm1.bindToDatGrid(int)': not all code paths return a value
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[tblPictures]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[tblPictures]
GO
CREATE TABLE [dbo].[tblPictures] (
[id] [int] NOT NULL ,
[Image] [varbinary] (50) NULL
) ON [PRIMARY]
GO