hi
i used this thread code to upload 2 image in table with same behcode and id
http://www.aspforums.net/Threads/530227/how-to-use-id-column/
in my page i have 2 file upload control some Text box button dropdown list and ...
that user complete their store information with these control and when they click on ImageButton2_Click1 and their information insert into table
protected void ImageButton2_Click1(object sender, ImageClickEventArgs e)
{
string data = Server.UrlDecode(Request.QueryString["BehCode3"]);
string price = RadioButton2.Checked ? TextBox1.Text : "noprice";
SqlCommand _cmd = new SqlCommand("insertproduct", _cn);
_cmd.CommandType = CommandType.StoredProcedure;
_cn.Open();
_cmd.Parameters.AddWithValue("@Name", txtname.Text);
_cmd.Parameters.AddWithValue("@Model", txtmodel.Text);
_cmd.Parameters.AddWithValue("@Description", CKEditorControl1.Text);
_cmd.Parameters.AddWithValue("@Price", price);
_cmd.Parameters.AddWithValue("@Classification", DDL1.SelectedItem.Text);
_cmd.Parameters.AddWithValue("@subset", DDL1.SelectedItem.Text);
_cmd.Parameters.AddWithValue("@behcode", data);
_cmd.Parameters.AddWithValue("@id", Convert.ToInt32(ViewState["Id"]));
_cmd.ExecuteNonQuery();
_cn.Close();
Response.Redirect(Request.Url.AbsoluteUri);
}
see here i use _cmd.Parameters.AddWithValue("@id", Convert.ToInt32(ViewState["Id"]));
that it insert all data according to this id
i define this id in one of my button that upload users image from fileupload
protected void BtnUpload_Click(object sender, EventArgs e)
{
string path = Server.MapPath(".") + "\\../image/House\\";
//4-Get File Name
string filename = System.IO.Path.GetFileName(fup1.PostedFile.FileName);
//5-Get File Exist and if (true)Generate New Name
while (System.IO.File.Exists(path + "\\" + filename))
filename = "1" + filename;
//6-Save File to Server
fup1.PostedFile.SaveAs(path + filename);
SqlCommand _cmd = new SqlCommand("Fileup1", _cn);
_cmd.CommandType = CommandType.StoredProcedure;
string data = Server.UrlDecode(Request.QueryString["BehCode3"]);
_cn.Open();
_cmd.Parameters.AddWithValue("@image", filename);
_cmd.Parameters.AddWithValue("@Behcode", data);
_cmd.Parameters.Add("@id", SqlDbType.Int).Direction = ParameterDirection.Output;
_cmd.ExecuteNonQuery();
ViewState["Id"] = _cmd.Parameters["@id"].Value.ToString();
_cn.Close();
so here users should select their image from this fileupload control untill their store information insert to table
my problem is maybe users don't want upload any image when they don't upload image it can't insert any data in table becuse of this
ViewState["Id"] = _cmd.Parameters["@id"].Value.ToString();
so now what should i do how i can define that if users didn't upload any page it insert other infomation
in table?
best regards