skip to main |
skip to sidebar
RSS Feeds
Now maintained at http://www.prithviraj.com.np
Now maintained at http://www.prithviraj.com.np
Sunday, October 21, 2012
By Unknown
comboBox2.Items.Clear(); if (checkBox1.Checked == true) { ConStr = "Data Source = " + comboBox1.Text.ToString() + ";Integrated Security = true;"; } else { ConStr = "Data Source = " + comboBox1.Text.ToString() + ";UID=" + textBox1.Text + ";pwd=" + textBox2.Text + ";"; } SqlConnection Conexion = new SqlConnection(ConStr); Conexion.Open(); label9.Visible = false; panel2.Visible = false; button2.Visible = true; panel1.Visible = true; groupBox1.Visible = true; DataTable tblDatabases = Conexion.GetSchema("Databases"); for (int i = 0; i <= tblDatabases.Rows.Count - 1; i++) { comboBox2.Items.Add(tblDatabases.Rows[i][0].ToString()); } Conexion.Close();
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e) { comboBox3.Items.Clear(); SqlConnection conx = new SqlConnection(ConStr + "Database ="+comboBox2.Text.ToString()+";"); conx.Open(); DataTable tblTables = conx.GetSchema("Tables"); for (int i = 0; i <= tblTables.Rows.Count - 1; i++) { comboBox3.Items.Add(tblTables.Rows[i][2].ToString()); } conx.Close(); }Here we are creating Connection String Everytime, because, It is changing every-time. Now this code will list all the Tables inside Database in Table Combo (combobox3): Code:
private void comboBox3_SelectedIndexChanged(object sender, EventArgs e) { comboBox4.Items.Clear(); SqlConnection conx = new SqlConnection(ConStr + "Database =" + comboBox2.Text.ToString() + ";"); conx.Open(); string tableName = comboBox3.SelectedItem.ToString(); SqlDataAdapter adp = new SqlDataAdapter("select * from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME = '"+comboBox3.SelectedItem.ToString()+"'",conx); DataTable tblColumns = new DataTable(); adp.Fill(tblColumns); for (int i = 0; i <= tblColumns.Rows.Count - 1; i++) { comboBox4.Items.Add(tblColumns.Rows[i][3].ToString()); } conx.Close(); }
private void textBox3_TextChanged(object sender, EventArgs e) { string QueryCon = ConStr; if (comboBox5.Text.ToString() == "like") { QueryStr = "SELECT * FROM " + comboBox3.Text.ToString() + " WHERE " + comboBox4.Text.ToString() + " " + comboBox5.Text.ToString() + " '%" + textBox3.Text + "%'"; } else { QueryStr = "SELECT * FROM " + comboBox3.Text.ToString() + " WHERE " + comboBox4.Text.ToString() + " " + comboBox5.Text.ToString() + " '" + textBox3.Text + "'"; } TxtQueryBox.Text = ConStr + "Database=" + comboBox2.Text.ToString() + ";"+"\n" + QueryStr; SqlDataAdapter adp = new SqlDataAdapter(QueryStr, ConStr+"Database="+comboBox2.Text.ToString()+";"); DataSet ds = new DataSet(); adp.Fill(ds); dataGridView1.DataSource = ds.Tables[0]; }
Feel free to write,
I will surely read your comment and revert you back as soon as possible...
November 7, 2012 at 8:33 PM
sir as this apps shows the result of select query i wanna shows the result of all yhe sql queries like insert update deleate etc....pls tell me that what should i do for that..
November 9, 2012 at 12:02 PM
Dear Sachin, I havn't really worked with that but it is Possible.
As in above codes , you can see that Command ( Query) is passed from Backend, you can directly write Query in Front End textbox and pass it to backend.
Ex.
Query = txtQuery.Text;
and txtQuery.Text in Front is >
CREATE TABLE [dbo].[MyTable] (
[col1] [int] NOT NULL PRIMARY KEY,
[col2] [varchar](20) NULL,
[col3] [datetime] NULL,
[UserID] [varchar] (20) NOT NULL
)
Etc.