<asp:Button id="SaveButton" Text="Save" runat="server" onclick="SaveButton_Click"> </asp:Button> <asp:Button id="VisualiseButton" Text="Visualise" runat="server" onclick="VisualiseButton_Click"> </asp:Button> <asp:RadioButtonList id="RadioButtonList2" runat="server" Visible="false" onselectedindexchanged="RadioButtonList2_SelectedIndexChanged" ></asp:RadioButtonList> <asp:RadioButtonList id="RadioButtonList1" runat="server" Visible="false" ></asp:RadioButtonList> <asp:Button id="SaveToDBButton" Text="Insert" runat="server" Visible="false" onclick="InsertButton_Click">
protected void SaveButton_Click(object sender, EventArgs e) { String selQuery = "SELECT id, name FROM categories"; try { con.Open(); SqlDataAdapter da = new SqlDataAdapter(selQuery, con); DataTable dt = new DataTable(); da.Fill(dt); RadioButtonList2.DataSource = dt; RadioButtonList2.DataTextField = "name"; RadioButtonList2.DataValueField = "id"; RadioButtonList2.DataBind(); RadioButtonList2.RepeatColumns = 3; RadioButtonList2.AutoPostBack = true; RadioButtonList2.Visible = true; } catch (SqlException ex) { } finally { if (con != null) { con.Close(); } } } protected void RadioButtonList2_SelectedIndexChanged(object sender, EventArgs e) { String catId = RadioButtonList2.SelectedValue; SqlCommand cmdselect = new SqlCommand("SELECT DISTINCT categoryId, linkTablesCategories.tableName, tableDescription FROM linkTablesCategories, tableDescriptions where linkTablesCategories.tableName = tableDescriptions.tableName and categoryId ='" + catId + "'"); RadioButtonList1.Items.Clear(); try { con.Open(); cmdselect.Connection = con; SqlDataReader dar = cmdselect.ExecuteReader(); if (dar.HasRows) { while (dar.Read()) { ListItem li = new ListItem(dar["tableName"].ToString(), dar["categoryId"].ToString()); li.Attributes.Add("title", dar["tableDescription"].ToString()); RadioButtonList1.Items.Add(li); } } RadioButtonList1.Visible = true; SaveToDBButton.Visible = true; } catch (SqlException ex) { //lblMessage.Text = ex.Message; } finally { cmdselect.Dispose(); if (con != null) { con.Close(); } } } protected void InsertButton_Click(object sender, EventArgs e) { String tableId=""; **tableId = RadioButtonList1.SelectedItem.Text;** String path = Server.MapPath("~/"); string filepath = path + Session["filepath"].ToString(); StreamReader sr = new StreamReader(filepath); string line = sr.ReadLine(); string[] value = line.Split(','); DataTable dt = new DataTable(); DataRow row; foreach (string dc in value) { dt.Columns.Add(new DataColumn(dc)); } while (!sr.EndOfStream) { value = sr.ReadLine().Split(','); if (value.Length == dt.Columns.Count) { row = dt.NewRow(); row.ItemArray = value; dt.Rows.Add(row); } } SqlBulkCopy bc = new SqlBulkCopy(con.ConnectionString, SqlBulkCopyOptions.TableLock); bc.DestinationTableName = tableId; bc.BatchSize = dt.Rows.Count; con.Open(); bc.WriteToServer(dt); bc.Close(); con.Close(); }
ListItem li = new ListItem(dar["tableName"].ToString(), dar["categoryId"].ToString());
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)