ajinkya112 Light Poster

I need to know if it is possible to store click event of a button in
a variable. I tried doing it but didn't get any solution.

Please help

Regards

hey thanks,

Problem solved

Hey Praveen,

I did it but still grid view not showing records.
I know "selectedIndex" property of combo box is 'int' data type.
I want to use that property to display records from table 'T1'.
And also the problem is that I dont want to specify any "name" instead of "s1".

So, now as we know that index is an int how can we use it in form2 to show records??

Thanks.

ajinkya112 Light Poster

Hi people I need some help here.
Here is the CODE :

[B]for Form1:[/B]

[CODE]

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace practice
{
public partial class Form1 : Form
{
Form2 obj;
public Form1()
{
InitializeComponent();
}

    string str1 = "Data Source=Blackgold;Initial Catalog=MIS;Integrated Security=True";

    private void button1_Click(object sender, EventArgs e)
    {

        string s = comboBox1.SelectedIndex.ToString();
        obj = new Form2(s);
        obj.Show();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(str1);
        con.Open();

        SqlCommand cmd = new SqlCommand("Select Name from company", con);
        SqlDataReader dr = cmd.ExecuteReader();
        while (dr.Read())
        {
            comboBox1.Items.Add(dr[0].ToString());
    }

        }

}

}
[/CODE]

[B]FORM2[/B]

[CODE]using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace practice
{
public partial class Form2 : Form
{
string s1;
public Form2(string s)
{
InitializeComponent();
Convert.ToInt16(s1);
Convert.ToInt16(s);
s1 = s;
}
string str1 = "Data Source=Blackgold;Initial Catalog=MIS;Integrated Security=True";

   SqlDataAdapter da;
   DataSet ds = new DataSet();

    private void Form2_Load(object sender, EventArgs e)
    {
        SqlConnection con1 = new SqlConnection(str1);
        con1.Open();
        if (s1 == "0")
        {
            //string ccm = s1.ToString();                
            string str2 = "Select C_ID, BillNo from T1 where C_NAME = " + s1 + "";
            da = new SqlDataAdapter(str2,con1);
            da.Fill(ds);
            dataGridView1.DataSource = ds.Tables[0].DefaultView;
        }
        else if (s1 == "1")
        {
            //string cmc = s1.ToString();
            string str3 = "Select C_ID, BillNo from T1 where C_NAME = "+ s1 + "";
            da = new SqlDataAdapter(str3, con1);
            da.Fill(ds);
            dataGridView1.DataSource = ds.Tables[0].DefaultView;
        }
    }
} 

[/CODE] ...

Hey People thanks for your help.
Thanks praveen.

Regards

Ajinkya

Here's My code :

[CODE] using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
Form2 ob;
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
string s;
s = comboBox.SelectedIndex;
ob = new Form2(s);
ob.Show();
}
}
}

for form2 :

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
public partial class Form2 : Form
{
string ss;
public Form2(string s)
{
InitializeComponent();
ss = s;
comboBox.SelectedIndex = ss;
}
}
}

[/CODE]

I want to compare the value of selected item in combo box and display its data accordingly(on click of a button). However it gives me error "The name comboBox.selectedIndex doesn't exist in current context". What do i do now?

ajinkya112 Light Poster

Hey Guys,

Currently, I am doing a project. I don't know how to pass a value from one windows form to another windows form using c#.net.

Suppose, I have two forms parent form and child form. Parent form consists of a

combo box & button and I want to pass selected item of combo box to my child form and that

item will be showing in a text box of child form. How can I do that?

Thanks and Regards

ajinkya112 Light Poster

Hey guys,

need your help once again. I want to create a global variable in
one form and then use it in another form.
I need to know of it is possible. If yes, then how do we do it.

Thanks And regards

ajinkya112 Light Poster

Example :

suppose i have a form1 and a form2.

form1 has a button on it which would display a message "Clicked" when clicked

And if form2 inherits form1. How can i change
the properties of that button and make display a message "Now Clicked" ?

please help.....:?:

@ddanbe...

naah.. i want tables with same name to be stored..
i know its not possible in same DB..but i tried doing it with two different DBs
n it din work either..

lemme paste my code....

[CODE]public void button1_Click(object sender, EventArgs e)
{

        if (textBox1.Text == "")
        {
            textBox1.Focus();
            errorProvider1.SetError(textBox1, "Please Enter Name of the company");
            MessageBox.Show("Enter the name of company");

        }
        else
        {

            string str;
            str = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Program Files\\DB1.accdb";

           string str2 = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Program Files\\DB2.accdb";

            OleDbConnection cd = new OleDbConnection(str);
            cd.Open();

            string strrr = "select * from Table1";
            OleDbCommand cmdb = new OleDbCommand(strrr, cd);

            OleDbDataReader drr = cmdb.ExecuteReader();

            if (drr.Read())
            {
                MessageBox.Show("noar");
            }

            try
            {

                string qry = "insert into Table1 values('" + textBox1.Text + "')";
                OleDbCommand cmd = new OleDbCommand(qry, cd);
                cmd.ExecuteNonQuery();
                MessageBox.Show("Company added successfully");
                OleDbCommand ccm = cd.CreateCommand();

               [COLOR="Green"]//table1[/COLOR]

                ccm.CommandText = "CREATE TABLE " + textBox1.Text + "(Nmb1 int, Nmb2 int)";

                ccm.ExecuteNonQuery();

                MessageBox.Show("Added");
                cd.Close();

                [COLOR="Green"]////table2[/COLOR]
               OleDbConnection con1 = new OleDbConnection(str2);

                con1.Open();

               OleDbCommand cmm = con1.CreateCommand(); 

               cmm.CommandText = "CREATE TABLE " + textBox2.Text + "(Password CHAR(10))";

                cmm.ExecuteNonQuery();
                con1.Close();

                MessageBox.Show("asdasd");

                Form2 f2 = new Form2();
                f2.Show();

            }

            catch(Exception)
            {
                MessageBox.Show("Already exist");
            }
            cd.Close();
        }

[/CODE]

[CODE]string code;
code = textBox.Text;
r = dp.Tables[Tablename].Rows.Find(code);
r.Delete();
db.Update(dp);[/CODE]

r is datarow.
dp is dataset
db is dataAdapter.

You can find the row that u want to delete by entering a column name.
And then this code would delete that row and would also update your table.

ajinkya112 Light Poster

How do i create two tables in a database
at same time from a windows form.??

how do i give them same name??

@Lolafuertes and JAY...

Thank you guys for your help..

lola especially you..

regards

ajinkya ragalwar

ajinkya112 Light Poster

i need to ask one more question....

[CODE]private void bbn_Click(object sender, EventArgs e)
{
OleDbDataAdapter ad;
DataSet ds1 = new DataSet();

        if (comboBox1.SelectedIndex == 0)
        {
            string str1 = "select * from '"+comboBox1.SelectedIndex+"'";
            OleDbConnection conn1 = new OleDbConnection(str);
            ad = new OleDbDataAdapter(str1, conn1);

            ad.Fill(ds1);
            dataGridView1.DataSource = ds1.Tables[0].DefaultView;[/CODE]

i want the button to select the data from combo box and then display the corresponding table in grid view...

however its giving me an error [CODE]ad.Fill(ds1)[/CODE] here...

it says syntax error..i know i need to write table name there...but i want it to read it from my [CODE]combobox.seleted index[/CODE]....

Any suggestions....

thanks and regards

@lolafuertes...

hey thankz a lot for your help...

i need to ask one more question....

[CODE]private void bbn_Click(object sender, EventArgs e)
{
OleDbDataAdapter ad;
DataSet ds1 = new DataSet();

        if (comboBox1.SelectedIndex == 0)
        {
            string str1 = "select * from '"+comboBox1.SelectedIndex+"'";
            OleDbConnection conn1 = new OleDbConnection(str);
            ad = new OleDbDataAdapter(str1, conn1);

            ad.Fill(ds1);
            dataGridView1.DataSource = ds1.Tables[0].DefaultView;[/CODE]

i want the button to select the data from combo box and then display the corresponding table in grid view...

however its giving me an error [CODE]ad.Fill(ds1)[/CODE] here...

it says syntax error..i know i need to write table name there...but i want it to read it from my [CODE]combobox.seleted index[/CODE]....

Any suggestions....

thanks and regards

ajinkya112 Light Poster

Hey folks,

I am making an application where i want to create some controls dynamically.

for instance..i hv a text box that takes the name of table and stores it in database.
Now, the thing i want is everytime a name is added and table is created...at the same time a form should also get created in order to display the data of recently created table.

pls help me this...please....

@LOLAFUERTES....

hey thanx for your reply...
yea..i m facing exact prblms tht u hv stated..

a) Allways show the same records at every refresh of the datagrid
b) All the rows shown have the same values
c) At every refresh, the data grid increases the number of rows, and the content of the new rows is exactly the same of the old rows

thanx

ajinkya112 Light Poster

Hey Guys,

I have a question...

I want to display data from two different tables into a single datagrid view.
Problem is i dnt wana join the tables. pls check this code

[code]private void bindgrid()
{
SqlConnection con = new SqlConnection(connStr);
con.Open();
str1 = "Select from wcl_et ";
str2 = "Select
from secl_et";
str3 = "select * from sccl_et";
ad = new SqlDataAdapter(str1, con);
ad.Fill(ds1, "wcl_et");
ad = new SqlDataAdapter(str2, con);
ad.Fill(ds2, "secl_et");
//ds1.Merge(ds2);
dataGridView1.DataSource = ds1.Tables[0].DefaultView;
//dataGridView1.DataSource = ds1;
//dataGridView1.DataBindings();
}

private void Form1_Load(object sender, EventArgs e)
{
bindgrid();
}

private void button1_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection(connStr);
ad = new SqlDataAdapter(str2, conn);
ad.Fill(ds2, "secl_et");
dataGridView1.DataSource = ds2.Tables[0].DefaultView;
}

private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{

}

private void button2_Click(object sender, EventArgs e)
{
SqlConnection conn1 = new SqlConnection(connStr);
ad = new SqlDataAdapter(str3, conn1);
ad.Fill(ds3, "sccl_et");
dataGridView1.DataSource = ds3.Tables[0].DefaultView;
}[/code]

the problem is...i want to display data of second table on the click of the button and i have written code for same. But if run this code it u wud find tht everytime u click button, it shows repeated records. Please help me with this....