private void button2_Click(object sender, EventArgs e) { //Field Declarations DateTime report_year = dateTimePicker1.Value; string firstname = textBox1.Text; string lastname = textBox2.Text; string property**le = textBox3.Text; string business**le = textBox4.Text; string address = textBox5.Text; string district = comboBox1.Text; //Floorplan File string floorplanpath1 = opendlg.FileName; string fpname = Path.GetFileName(floorplanpath1); FileStream fpstream = new FileStream(fpname, FileMode.Open, FileAccess.Read); BinaryReader fpreader = new BinaryReader(fpstream); FileInfo fpfi = new FileInfo(fpname); long fpsize = fpfi.Length; byte[] floorplan = System.IO.File.ReadAllBytes(fpname); //Reportsubmitted File string reportsubmittedpath1 = opendlg.FileName; string rsname = Path.GetFileName(reportsubmittedpath1); FileStream rsstream = new FileStream(rsname, FileMode.Open, FileAccess.Read); BinaryReader rsreader = new BinaryReader(rsstream); FileInfo rsfi = new FileInfo(rsname); long rssize = rsfi.Length; byte[] reportsubmitted = System.IO.File.ReadAllBytes(rsname); //Request File string requestpath1 = opendlg.FileName; string rname = Path.GetFileName(requestpath1); FileStream rstream = new FileStream(rname, FileMode.Open, FileAccess.Read); BinaryReader rreader = new BinaryReader(rstream); FileInfo rfi = new FileInfo(rname); long rsize = rfi.Length; byte[] request = System.IO.File.ReadAllBytes(rname); DateTime review = dateTimePicker2.Value; //Establish Database Connection try { SqlConnection connection = new SqlConnection(@"Data Source=localhost;Initial Catalog=fireprevention;User ID=sa;P**word=pussyopac"); const string query = "insert into [reports] ([report_year], [firstname], [lastname], [property**le], [business**le], [address], [district], [floorplan], [reportsubmitted], [request], [review]) values (@reports, @firstname, @lastname, @property**le, @business**le, @address, @district, @floorplan, @reportsubmitted, @request, @review)"; SqlCommand command = new SqlCommand(query, connection); command.Parameters.AddWithValue("@report_year", report_year); command.Parameters.AddWithValue("@firstname", firstname); command.Parameters.AddWithValue("@lastname", lastname); command.Parameters.AddWithValue("@property**le", property**le); command.Parameters.AddWithValue("@business**le", business**le); command.Parameters.AddWithValue("@address", address); command.Parameters.AddWithValue("@district", district); command.Parameters.AddWithValue("@floorplan", floorplan); command.Parameters.AddWithValue("@reportsubmitted", reportsubmitted); command.Parameters.AddWithValue("@request", request); command.Parameters.AddWithValue("@review", review); const string queryfp = "insert into [floorplan] ([fpsize], [floorplan], [fpname]) values (@fpsize, @floorplan, @fpname)"; command.Parameters.AddWithValue("@fpsize", fpsize); command.Parameters.AddWithValue("@fpplan", floorplan); command.Parameters.AddWithValue("@fpname", fpname); SqlCommand command1 = new SqlCommand(queryfp, connection); const string queryrs = "insert into [reportsubmitted] ([rssize], [reportsubmitted], [rsname]) values (@rssize, @reportsubmitted, @rsname)"; command.Parameters.AddWithValue("@rssize", rssize); command.Parameters.AddWithValue("@rreportsubmitted", reportsubmitted); command.Parameters.AddWithValue("@rsname", rsname); SqlCommand command2 = new SqlCommand(queryrs, connection); const string queryr = "insert into [request] ([rsize], [request], [rname]) values (@rsize, @request, @rname)"; command.Parameters.AddWithValue("@rsize", rsize); command.Parameters.AddWithValue("@request", request); command.Parameters.AddWithValue("@rname", rname); SqlCommand command3 = new SqlCommand(queryr, connection); command.Connection.Open(); command1.Connection.Open(); command2.Connection.Open(); command3.Connection.Open(); command.ExecuteNonQuery(); command1.ExecuteNonQuery(); command2.ExecuteNonQuery(); command3.ExecuteNonQuery(); fpreader.Close(); fpstream.Close(); rsreader.Close(); rsstream.Close(); rreader.Close(); rstream.Close(); connection.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } //dateTimePicker1.Enabled = false; //textBox1.Enabled = false; //textBox2.Enabled = false; //textBox3.Enabled = false; //textBox4.Enabled = false; //textBox5.Enabled = false; //comboBox1.Enabled = false; //dateTimePicker2.Enabled = false; //button2.Enabled = false; //button3.Enabled = false; //button4.Enabled = false; //button5.Enabled = false; //button6.Enabled = false; } }
i am new to programming in c# so bear with me please as my source code is all jumbled up..
i have 4 databases. reports - floorplan - reportsubmitted - request.
My issue is i want to knwo whwen i upload the report details ialso want to upload multiple binary files with that same report..