 |
|
น้องลองเขียนโค้ดดูแล้วให้มันเซฟทับข้อมูลเดิม แต่มันไม่ทับข้อมูลเดิม
ต้องทำไงค่ะ น้องเอาโค้ดมาให้ดูด้วย
string flashup = "";
if (fup_flash.HasFile)
{
fup_flash.SaveAs(Server.MapPath("~/backend/image/product/" + fup_flash.FileName));
flashup = "~/backend/image/product/" + fup_flash.FileName;
}
SqlConnection con = new SqlConnection(connect);
con.Open();
string sql = "select * from flash";
SqlCommand com = new SqlCommand(sql,con);
com.ExecuteNonQuery();
DataTable dtb = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(sql, con);
da.Fill(dtb);
if (dtb.Rows.Count > 0)
{
SqlConnection con1 = new SqlConnection(connect);
con1.Open();
System.Text.StringBuilder str = new System.Text.StringBuilder();
str.AppendLine("select replace(flashPic,'flashPic','@flashPic') from flash");
SqlCommand com1 = new SqlCommand(str.ToString(),con);
com1.Parameters.AddWithValue("@flashPic",flashup);
com1.ExecuteReader();
con1.Dispose();
}
else
{
SqlConnection con2 = new SqlConnection(connect);
con2.Open();
System.Text.StringBuilder str = new System.Text.StringBuilder();
str.AppendLine("insert into flash (flashPic) values (@flashPic) ");
SqlCommand com2 = new SqlCommand(str.ToString(), con);
com2.Parameters.AddWithValue("@flashPic", flashup);
com2.ExecuteReader();
con2.Dispose();
}
con.Dispose();
ขอบคุณล่วงหน้าค่ะ
Tag : .NET, Ms SQL Server 2005, Web (ASP.NET), C#
|
|
 |
 |
 |
 |
Date :
2011-02-22 13:50:44 |
By :
ling-keaw |
View :
1178 |
Reply :
3 |
|
 |
 |
 |
 |
|
|
|
 |