これが私のコードです。エラーメッセージは
パラメータ @event_image が指定されていません
パラメータとして画像名を送信するには? ブレークポイントを保持していると、 に入ることさえありませんIf(fileupload1.HasFile)
。
イメージをフォルダーに保存する必要があり、パスを sql db に保存する必要があります
{
conn.Open();
string postdate = txtpostdate.Text;
string unpostdate = txtunpostdate.Text;
string name = txtname.Text;
string description = txtdescription.Text;
string country = dropcountry.SelectedItem.ToString();
string multidate = txtstartdae.Text;
string startend = dropstarttime.SelectedItem.ToString();
string drop1m = dropti1m.SelectedItem.ToString();
string dropme1h = droptimeend1h.SelectedItem.ToString();
string drop2m = droptime2m.SelectedItem.ToString();
string notes = txtnotes.Text;
string prevlocation = droplocation.SelectedItem.ToString();
string locationname = txtslocname.Text;
string addres1 = txtsLocAddress1.Text;
string addres2 = txtsLocAddress2.Text;
string city = txtsLocCity.Text;
string state = dropstate.SelectedItem.ToString();
string zipcode = txtsLocZip.Text;
string phonenumber = txtsLocPhone.Text;
string faxnumber = txtsLocFax.Text;
string notes2 = textnotes2.Text;
SqlCommand cmd = new SqlCommand("InsertEvents", conn);
cmd.CommandType = CommandType.StoredProcedure;
//SqlCommand cmd = new SqlCommand("insert into pa_events(event_postdate,event_unpostdate,event_canvisitorsregisters,event_eventname,event_description,event_image,event_multydateevent,event_startdate,event_enddate,event_start,event_end,event_notes,location_name,location_addres1,location_addres2,location_cites,location_state,location_zipcode,location_phonenumber,location_faxnumber,location_notes,event_country) values(@event_postdate,@event_unpostdate,@event_canvisitorsregisters,@event_eventname,@event_description,@event_image,@event_multydateevent,@event_startdate,@event_enddate,@event_start,@event_end,@event_notes,@location_name,@location_addres1,@location_addres2,@location_cites,@location_state,@location_zipcode,@location_phonenumber,@location_faxnumber,@location_notes,@event_country)", conn);
if (fileupload1.HasFile)
{
imagename = fileupload1.FileName;
int length = fileupload1.PostedFile.ContentLength;
fileupload1.SaveAs(Server.MapPath("~\\images\\" + imagename));
s = "~\\images\\" + imagename + "";
}
if (radioyes.Checked == false && !radiono.Checked == false)
{
lblmsg.Text = "Please Select canve Register Yes! or No!";
}
if (radioyes.Checked == true)
{
cmd.Parameters.AddWithValue("@event_canvisitorsregisters", SqlDbType.VarChar).Value = "Y";
}
else
{
cmd.Parameters.AddWithValue("@event_canvisitorsregisters", SqlDbType.VarChar).Value = "N";
}
if (radiomultyyes.Checked == true)
{
cmd.Parameters.AddWithValue("@event_multydateevent", SqlDbType.VarChar).Value = "Y";
}
else
{
cmd.Parameters.AddWithValue("@event_multydateevent", SqlDbType.VarChar).Value = "N";
}
**cmd.Parameters.AddWithValue("@event_image", s);**
cmd.Parameters.AddWithValue("@event_postdate", postdate);
cmd.Parameters.AddWithValue("@event_unpostdate", unpostdate);
cmd.Parameters.AddWithValue("@event_eventname", name);
cmd.Parameters.AddWithValue("@event_description", description);
cmd.Parameters.AddWithValue("@event_country", country);
cmd.Parameters.AddWithValue("@event_startdate", startend);
cmd.Parameters.AddWithValue("@event_enddate", drop1m);
cmd.Parameters.AddWithValue("@event_start", dropme1h);
cmd.Parameters.AddWithValue("@event_end", drop2m);
cmd.Parameters.AddWithValue("@event_notes", notes);
cmd.Parameters.AddWithValue("@location_name", locationname);
cmd.Parameters.AddWithValue("@location_addres1", addres1);
cmd.Parameters.AddWithValue("@location_addres2", addres2);
cmd.Parameters.AddWithValue("@location_cites", city);
cmd.Parameters.AddWithValue("@location_state", state);
cmd.Parameters.AddWithValue("@location_zipcode", zipcode);
cmd.Parameters.AddWithValue("@location_phonenumber", phonenumber);
cmd.Parameters.AddWithValue("@location_faxnumber", faxnumber);
cmd.Parameters.AddWithValue("@location_notes", notes2);
//if (fileupload1.PostedFile != null && fileupload1.PostedFile.FileName != "")
//
int i = cmd.ExecuteNonQuery();
if (i != 0)
{
lblmsg.Text = "record is inserted";
}
else
{
lblmsg.Text = "record is not inserted";
}
conn.Close();
}