what is worng this my code,

Jan 25 2015 11:14 AM
what is worng this my code,
I have 3 fileupload
<table>


<tr>


<td>Provinsi </td>


<td><asp:DropDownList ID="cmbprovinsi" runat="server" Height="23px" Width="301px"


onselectedindexchanged="cmbprovinsi_SelectedIndexChanged" AutoPostBack="true">


</asp:DropDownList> </td>


</tr>


<tr>


<td>Kabupaten/Kota </td>


<td><asp:DropDownList ID="cmbkabupaten" runat="server" Height="23px"


Width="299px" onselectedindexchanged="cmbkabupaten_SelectedIndexChanged">


</asp:DropDownList> </td>


</tr>


<tr>


<td> Sektor/Bidang </td>


<td><asp:DropDownList ID="cmbsektor" runat="server" Height="25px" Width="132px">


</asp:DropDownList> </td>


</tr>


<tr>


<td> Perda Pembentukan </td>


<td>


<asp:FileUpload ID="FileUpload1" runat="server" class="multi" />


</td>


</tr>


<tr>


<td> Perda Pengelolaan </td>


<td>


<asp:FileUpload ID="FileUpload2" runat="server" />


</td>


</tr>


<tr>


<td> Perda Retribusi </td>


<td>


<asp:FileUpload ID="FileUpload3" runat="server" /> </td>


</tr>


<tr>


<td></td>


</tr>


<tr>


<td></td>


<td>


<asp:Button ID="btnsimpan" runat="server" Text="Simpan"


onclick="btnsimpan_Click" /><asp:Button ID="btnbatal"


runat="server" Text="Batal" /> </td>


</tr>


</table>






protected void btnsimpan_Click(object sender, EventArgs e)




{





// Get the HttpFileCollection


HttpFileCollection hfc = Request.Files;


for (int i = 0; i < hfc.Count; i++)




{


HttpPostedFile hpf = hfc[i];


string fileName1 = Path.GetFileName(FileUpload1.FileName);







if (hpf.ContentLength > 0)




{


FileUpload1.SaveAs(Server.MapPath("perda_pembentukan") + "\\" +


System.IO.Path.GetFileName(hpf.FileName));




}


string fileName2 = Path.GetFileName(FileUpload2.FileName);


string fileName3 = Path.GetFileName(FileUpload3.FileName);


FileUpload2.SaveAs(Server.MapPath("resource/perda_pengelolaan/") + "\\" +


System.IO.Path.GetFileName(hpf.FileName));


FileUpload3.SaveAs(Server.MapPath("resource/Perda_retribusi/") + "\\" +


System.IO.Path.GetFileName(hpf.FileName));


string Queryinsert = "INSERT INTO tbl_peraturan (propinsi_id,kabupaten_id,sektor_id,namafile1,namafile2,namafile3,perda_pembentukan,perda_pengelolaan,perda_retribusi)" +


" VALUES(@propinsi_id,@kabupaten_id,@sektor_id,@namafile1,@namafile2,@namafile3,@perda_pembentukan,@perda_pengelolaan,@perda_retribusi)";








using (MySqlConnection con = new MySqlConnection(strConnString))




{


using (MySqlCommand cmd = new MySqlCommand())




{


cmd.Connection = con;


cmd.CommandType = CommandType.Text;




cmd.CommandText = Queryinsert;


cmd.Parameters.AddWithValue("@propinsi_id", cmbprovinsi.Text);


cmd.Parameters.AddWithValue("@kabupaten_id", cmbkabupaten.Text);


cmd.Parameters.AddWithValue("@sektor_id", cmbsektor.Text);


cmd.Parameters.AddWithValue("@namafile1", fileName1);


cmd.Parameters.AddWithValue("@namafile2", fileName2);


cmd.Parameters.AddWithValue("@namafile3", fileName3);


cmd.Parameters.AddWithValue("@perda_pembentukan", "perda_pembentukan/" + fileName1);


cmd.Parameters.AddWithValue("@perda_pengelolaan", "resource/perda_pengelolaan/" + fileName2);


cmd.Parameters.AddWithValue("@perda_retribusi", "resource/Perda_retribusi/" + fileName3);


try




{


con.Open();


cmd.ExecuteNonQuery();


}


finally




{


con.Close();


}


}


}





}



Answers (9)