Posts Tagged ‘c#.net’

How to change the location of a control at runtime in c#?

February 6, 2009

Changing the position of control at runtime

Label1.Location = new Point(X position,Y position);

Udhaya

Pisquare

How to add controls to a form at runtime?

February 5, 2009

Dynamic creation of controls

Label lbl = new Label();

this.Controls.Add(lbl);

lbl.Name = lblName;

lbl.Text = “Name”;

Udhaya

Pisquare

Simsys

How to make TextBox accept only Deecimal Values?

December 9, 2008
How to make textbox to allow decimal values in textbox in c#.net windows forms.

private void txtRate_KeyPress(object sender, KeyPressEventArgs  e)
{
    if (!char.IsDigit(e.KeyChar) && !char.IsControl(e.KeyChar) &&   !(e.KeyChar.Equals('.')))
          e.Handled =true;
}
Udhaya
PiSquare

How to bind Combobox to a table field?

November 28, 2008

Binding ComboBox to a table using Stored Procedure

SqlDataAdapter da = new SqlDataAdapter(“StoredProcedureName”,Connection);
da.SelectCommand.CommandType = CommandType.StoredProcedure;
da.SelectCommand.Parameters.Add(new SqlParameter(“@Param1”, Value for @Param1));
DataSet ds = new DataSet( );
da.Fill(ds, “TableName”);
dataGridView1.DataSource = ds;
dataGridView1.DataMember = “TableName”;

Binding ComboBox to a table using Command

Connection.Open();

SqlDataAdapter da = new SqlDataAdapter(“select Uname from Table1”, Connection);

DataSet ds = new DataSet( );

da.Fill(ds, “Table1”);
comboBox1.DataSource =ds.Tables[0];
comboBox1.DisplayMember = “Uname”;

Connection1.Close();

Udhaya

PiSquare Soft Solns

How to execute Stored Procedure in C#

November 28, 2008

Executing Stored Procedure in C#

SQLCommand Command = new SqlCommand(“StoredProcedureName”, Connection);
Command.CommandType = CommandType.StoredProcedure;
Command.Parameters.Add(new SqlParameter(“@Param1”, comboBox1.Text));

//@Param1-Var Name you declare in Stored Procedure;comboBox1.Text-Value to be passed for that Var
Command.Parameters.Add(new SqlParameter(“@Param2”, textBox1.Text));
Command.Parameters.Add(new SqlParameter(“@Param3”, dateTimePicker1.Value));

Command.ExecuteNonQuery();

Udhaya

PiSquare

How to use DataGrid in C# .Net?

November 1, 2008

First place the DataGridView Control in the form.In the coding add the namespasce

using System.Data.SqlClient;

then initialize SqlConnection to ConnString as public (i.e)next to public Form1( ) {InitializeComponent( );}

SqlConnection con = new SqlConnection(“Your Connection String”);

DataSet ds;

Inside any event such as Form_load or button1_click add the code

SqlDataAdapter da=new SqlDataAdapter(“select * from table1”,con);

ds=new DataSet();

da.Fill(ds,”table1″);

dataGridView1.DataSource=ds;

dataGridView1.DataMember=”table1″;

By

Udhaya