sitara24
یک شنبه 17 اردیبهشت 1391, 22:49 عصر
بچه ها
من تو سایت خیلی سرچ کردم ولی اونی که میخواستم رو پیدا نکردم
چند تاشو امتحان کردم ولی جواب نداد.کد منو ببینید و اگه لطف کنید راهنماییم کنین ممنون میشه.
string TypeImage = "nul";
byte[] Content = new byte[0];
bool FileOK = false;
if (Validation())
{
string strConn;
NameValueCollection nv = new NameValueCollection();
nv = ConfigurationManager.AppSettings;
strConn = nv.Get("connectionstring");
SqlConnection connection = new SqlConnection();
connection.ConnectionString = strConn;
SqlCommand cmd = new SqlCommand();
try
{
if (ImageUpload.HasFile)
{
if (ImageUpload.PostedFile.ContentType == "image/gif" || ImageUpload.PostedFile.ContentType == "image/jpeg" || ImageUpload.PostedFile.ContentType == "image/pjpeg" || ImageUpload.PostedFile.ContentType == "image/jpg" || ImageUpload.PostedFile.ContentType == "image/png" || ImageUpload.PostedFile.ContentType == "image/x-png")
{
if (ImageUpload.FileBytes.Length < 200000)
{
TypeImage = ImageUpload.PostedFile.ContentType;
Content = ImageUpload.FileBytes;
FileOK = true;
}
else
LblErrHajm.Visible = true;
}
else
LblErrType.Visible = true;
}
if (FileOK)
{
cmd.Connection = connection;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "SPF_insertImage";
cmd.Parameters.Add("@Title", SqlDbType.NVarChar);
cmd.Parameters.Add("@FileImage", SqlDbType.Image);
cmd.Parameters.Add("@FileContent", SqlDbType.NVarChar);
cmd.Parameters["@Title"].Value = TxBTitle.Text;
cmd.Parameters["@FileImage"].Value = Content;
cmd.Parameters["@FileContent"].Value = TypeImage;
connection.Open();
cmd.ExecuteNonQuery();
connection.Close();
clear();
LblOk.Visible = true;
GrdImage.DataBind();
}
}
catch
{
clear();
Lblerror.Visible = true;
connection.Close();
}
از اینجا میفرستم تو بانک
حالا میخوام نشونش بدم
یا تو گرید یا دیتا لیست
با گرین این کا رو انجام دادم
<asp:GridView ID="GrdImage" runat="server" AllowPaging="True"
AutoGenerateColumns="False" CellPadding="4" DataSourceID="SqlDataSource1"
ForeColor="#333333" GridLines="None">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField DataField="Title" HeaderText="عنوان" />
<asp:ImageField DataImageUrlField="FileImage" HeaderText="تصویر">
</asp:ImageField>
</Columns>
<EditRowStyle BackColor="#7C6F57" />
<FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#E3EAEB" />
<SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F8FAFA" />
<SortedAscendingHeaderStyle BackColor="#246B61" />
<SortedDescendingCellStyle BackColor="#D4DFE1" />
<SortedDescendingHeaderStyle BackColor="#15524A" />
</asp:GridView>
ولی بازم نشون نمیده.از توی خود گرید به دیتا بیس باند کردم
لطفا راهنمایی کنید.
من تو سایت خیلی سرچ کردم ولی اونی که میخواستم رو پیدا نکردم
چند تاشو امتحان کردم ولی جواب نداد.کد منو ببینید و اگه لطف کنید راهنماییم کنین ممنون میشه.
string TypeImage = "nul";
byte[] Content = new byte[0];
bool FileOK = false;
if (Validation())
{
string strConn;
NameValueCollection nv = new NameValueCollection();
nv = ConfigurationManager.AppSettings;
strConn = nv.Get("connectionstring");
SqlConnection connection = new SqlConnection();
connection.ConnectionString = strConn;
SqlCommand cmd = new SqlCommand();
try
{
if (ImageUpload.HasFile)
{
if (ImageUpload.PostedFile.ContentType == "image/gif" || ImageUpload.PostedFile.ContentType == "image/jpeg" || ImageUpload.PostedFile.ContentType == "image/pjpeg" || ImageUpload.PostedFile.ContentType == "image/jpg" || ImageUpload.PostedFile.ContentType == "image/png" || ImageUpload.PostedFile.ContentType == "image/x-png")
{
if (ImageUpload.FileBytes.Length < 200000)
{
TypeImage = ImageUpload.PostedFile.ContentType;
Content = ImageUpload.FileBytes;
FileOK = true;
}
else
LblErrHajm.Visible = true;
}
else
LblErrType.Visible = true;
}
if (FileOK)
{
cmd.Connection = connection;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "SPF_insertImage";
cmd.Parameters.Add("@Title", SqlDbType.NVarChar);
cmd.Parameters.Add("@FileImage", SqlDbType.Image);
cmd.Parameters.Add("@FileContent", SqlDbType.NVarChar);
cmd.Parameters["@Title"].Value = TxBTitle.Text;
cmd.Parameters["@FileImage"].Value = Content;
cmd.Parameters["@FileContent"].Value = TypeImage;
connection.Open();
cmd.ExecuteNonQuery();
connection.Close();
clear();
LblOk.Visible = true;
GrdImage.DataBind();
}
}
catch
{
clear();
Lblerror.Visible = true;
connection.Close();
}
از اینجا میفرستم تو بانک
حالا میخوام نشونش بدم
یا تو گرید یا دیتا لیست
با گرین این کا رو انجام دادم
<asp:GridView ID="GrdImage" runat="server" AllowPaging="True"
AutoGenerateColumns="False" CellPadding="4" DataSourceID="SqlDataSource1"
ForeColor="#333333" GridLines="None">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField DataField="Title" HeaderText="عنوان" />
<asp:ImageField DataImageUrlField="FileImage" HeaderText="تصویر">
</asp:ImageField>
</Columns>
<EditRowStyle BackColor="#7C6F57" />
<FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#E3EAEB" />
<SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F8FAFA" />
<SortedAscendingHeaderStyle BackColor="#246B61" />
<SortedDescendingCellStyle BackColor="#D4DFE1" />
<SortedDescendingHeaderStyle BackColor="#15524A" />
</asp:GridView>
ولی بازم نشون نمیده.از توی خود گرید به دیتا بیس باند کردم
لطفا راهنمایی کنید.