Tuesday, December 21, 2010
source code site list c#
http://csharp4newbies.com/csharp_programming.html
http://cplus.about.com/od/codelibraryfo2/A_Library_of_Software_written_in_C_with_full_source_code.htm
Saturday, November 27, 2010
Thursday, November 11, 2010
datagridview control column row programitically
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 3)
{
MessageBox.Show((e.RowIndex + 1) + " Row " + (e.ColumnIndex + 1) + " Column button clicked ");
}
}
private void button1_Click_1(object sender, EventArgs e)
{
dataGridView1.ColumnCount = 3;
dataGridView1.Columns[0].Name = "Product ID";
dataGridView1.Columns[1].Name = "Product Name";
dataGridView1.Columns[2].Name = "Product Price";
string[] row = new string[] { "1", "Product 1", "1000" };
dataGridView1.Rows.Add(row);
row = new string[] { "2", "Product 2", "2000" };
dataGridView1.Rows.Add(row);
row = new string[] { "3", "Product 3", "3000" };
dataGridView1.Rows.Add(row);
row = new string[] { "4", "Product 4", "4000" };
dataGridView1.Rows.Add(row);
DataGridViewButtonColumn btn = new DataGridViewButtonColumn();
dataGridView1.Columns.Add(btn);
btn.HeaderText = "Click Data";
btn.Text = "Click Here";
btn.Name = "btn";
btn.UseColumnTextForButtonValue = true;
DataGridViewButtonColumn btn1 = new DataGridViewButtonColumn();
dataGridView1.Columns.Add(btn1);
btn1.HeaderText = "Click Data";
btn1.Text = "Click Here";
btn1.Name = "btn";
btn1.UseColumnTextForButtonValue = true;
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 3)
{
string rup = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
if (rup == "Click Here")
{
MessageBox.Show("this is test");
}
MessageBox.Show((e.RowIndex + 1) + " Row " + (e.ColumnIndex + 1) + " Column button clicked ");
}
}
c# connecting mysql and select ,insert ,delete
How to include :
1. Add Reference
2. Browse
3. Select File 'MySql.Data.dll'
at
C:\Program Files\MySQL\MySQL Connector Net
1.0.3\bin.\NET 1.1
4. You put code
using MySql.Data.MySqlClient;
Create a connection with mysql database :
MySqlConnection conn = new MySqlConnection("Network Address=localhost;" + "Initial Catalog='test';" +"Persist Security Info=no;" + "User Name='root';" + "Password=''");
public void Open();
As you can see, this method doesn't take any argument.
The MySqlConnection object that calls it is responsible
to get the connection string ready. If the connection
fails, the compiler would throw a MySqlException exception.
If the connection string doesn't contain a data source or
server, the compiler would throw an
InvalidOperationException
exception.
Select Data :
To read data from a mysql table add following code under a button .
MySqlConnection conn = new MySqlConnection("Network Address=localhost;" + "Initial Catalog='test';" +"Persist Security Info=no;" +
"User Name='root';" +
"Password=''");
MySqlCommand command = conn.CreateCommand();
MySqlDataReader Reader;
command.CommandText = "select name from student where id='1'";
conn.Open();
Reader = command.ExecuteReader();
while (Reader.Read())
{
string thisrow = "";
for (int i = 0; i < Reader.FieldCount;i++)
thisrow += Reader.GetValue(i).ToString() + ",";
MessageBox.Show(thisrow);
}
conn.Close();
Insert Data:
MySqlConnection conn = new MySqlConnection("Network Address=localhost;" + "Initial Catalog='test';" + "Persist Security Info=no;" + "User Name='root';" +"Password=''");
conn.Open();
MySqlCommand command = conn.CreateCommand();
command.CommandText = "insert into student(name,address)values('sanjoy','kaunia')";
MySqlDataReader result = command.ExecuteReader();
MessageBox.Show("successfully inserted");
result.Close();
conn.Close();
Delete Data:
MySqlConnection conn = new MySqlConnection("Network Address=localhost;" + "Initial Catalog='test';" + "Persist Security Info=no;" +
"User Name='root';" +
"Password=''");
conn.Open();
MySqlCommand command = conn.CreateCommand();
command.CommandText = "delete from student where id='1'";
MySqlDataReader result = command.ExecuteReader();
MessageBox.Show("successfully deleted");
result.Close();
conn.Close();
Thursday, October 15, 2009
How to pass parameter in Crystal report from c#
private void button1_Click(object sender, EventArgs e){ ReportDocument cryRpt = new ReportDocument();cryRpt.Load("PUT CRYSTAL REPORT PATH HERE\CrystalReport1.rpt");ParameterFieldDefinitions crParameterFieldDefinitions ;ParameterFieldDefinition crParameterFieldDefinition ;ParameterValues crParameterValues = new ParameterValues();ParameterDiscreteValue crParameterDiscreteValue = new ParameterDiscreteValue();crParameterDiscreteValue.Value = textBox1.Text;crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields;crParameterFieldDefinition = crParameterFieldDefinitions["Customername"];crParameterValues = crParameterFieldDefinition.CurrentValues;crParameterValues.Clear();crParameterValues.Add(crParameterDiscreteValue);crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);crystalReportViewer1.ReportSource = cryRpt;crystalReportViewer1.Refresh();}
private void button1_Click(object sender, EventArgs e){ ReportDocument cryRpt = new ReportDocument();ParameterFieldDefinitions crParameterFieldDefinitions ;ParameterFieldDefinition crParameterFieldDefinition ;ParameterValues crParameterValues = new ParameterValues();ParameterDiscreteValue crParameterDiscreteValue = new ParameterDiscreteValue();crParameterDiscreteValue.Value = textBox1.Text;crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields;crParameterFieldDefinition = crParameterFieldDefinitions["Customername"];crParameterValues = crParameterFieldDefinition.CurrentValues;crParameterValues.Clear();crParameterValues.Add(crParameterDiscreteValue);crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);crystalReportViewer1.ReportSource = cryRpt;crystalReportViewer1.Refresh();}
Wednesday, September 30, 2009
How to clear data gridview ?
dataGridView1.Rows.Clear();
Monday, August 31, 2009
How tom make right click option in c# winform
How to view windows calculator from program c#
- take a new project named - calculatorviewer solution explorer autometically created
- take a button in your form .
- use namespace System.Runtime.InteropServices;
- button click event write the folowwing code
[DllImport("shell32.dll")]private static extern long ShellExecute(IntPtr hwnd, string lpOperation, string lpFile, string lpParameters, string lpDirectory, int nShowCmd);[DllImport("user32.dll")]private static extern int FindWindow(string lpClassName, string lpWindowName);[DllImport("user32.dll")]private static extern int SendMessage(int hWnd, uint Msg, int wParam, int lParam);[DllImport("user32.dll")]private static extern int GetParent(int hWnd);[DllImport("user32.dll", SetLastError = true)]private static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string className, string windowTitle);//Gets window attributes[DllImport("USER32.DLL")]private static extern int GetWindowLong(IntPtr hWnd, int nIndex);private const int WM_COMMAND = 0x0112;private const int WM_CLOSE = 0xF060;private const int BN_CLICKED = 245;private const int GWL_ID = -12;IntPtr hwndChild = IntPtr.Zero;IntPtr hwnd = IntPtr.Zero;System.Diagnostics.Process.Start("Calc");
How to pass value one winform to another winform c#
mychildform newchild=new mychildform(myvalue) ;newchild.showdialog() ;
public string globalvalue ;public mychildform(string initialValue){InitializeComponent();ValueFromParent = initialValue;}
public string ValueFromParent{set{globalvalue= value;}}
how to make a form mdi c#
myform newmyform=new myform() ;
newmyform.mdiparent=this ;
newmyform.show() ;
to call form in child chil form
myform newmyform=new myform() ;
newmyform.mdiparent=this.mdiparent ;
newmyform.show()
Sunday, August 30, 2009
How to close previous form to new form open autometically C#
private void btnlogin_Click(object sender, EventArgs e){mainform newmainwindow = new mainform();newmainwindow.Show(this);this.Hide();}
protected override void OnClosing(CancelEventArgs e){Owner.Close();}
How to Edit a Connection String C#
You can modify connection information that is saved in application settings by using the Project Designer.
To edit a connection string stored in application settings
In Solution Explorer, double-click the My Project icon (Visual Basic) or Properties icon (Visual C# or Visual J#) to open the Project Designer.
Select the Settings tab.
Locate the connection you want to edit and select the text in the Value box.
Edit the connection string in the Value box.
-or-
Click the ellipses in the Value box to edit your connection with the Connection Properties dialog box. For more information.
You can modify connection information that is saved in code by using the Dataset Designer.
To edit a connection string stored in code
In Solution Explorer, double-click the dataset (.xsd file) with the connection you want to edit.
Select the TableAdapter or query with the connection you want to edit.
In the Properties window expand the DefaultConnection node.
To quickly modify the connection string, edit the ConnectionString property.
Saturday, August 29, 2009
The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.
insert into mydatetime(mydatetime)values('"+ string.Format("{0:yyyy/MM/dd}",dt) +"')
it will work well .
Thursday, August 27, 2009
how to set combobox value from database c#
dbconnection dbconn = new dbconnection();
SqlDataReader rdr = null;
DataTable dt = new DataTable();
string sqlquery = "select * from student where status='1'";
try
{
dbconn.connection.Open();
SqlCommand cmd4 = new SqlCommand(sqlquery, dbconn.connection);
rdr = cmd4.ExecuteReader();
dt.Columns.Add("Id");
dt.Columns.Add("name");
while (rdr.Read())
{
int id = (int)rdr["id"];
string name= (string)rdr["name"];
string comboid = Convert.ToString(id);
dt.Rows.Add(id, name);
}
dt.AcceptChanges();
this.comboBox1.DisplayMember = "name";
this.comboBox1.ValueMember = "Id";
this.comboBox1.DataSource = dt;
if (rdr != null)
{
rdr.Close();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
how to make datagridview cell format in math round
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
decimal each = decimal.Parse( this.dataGridView1.Rows[i].Cells[2].Value.ToString());
decimal decimalcorund = decimal.Round(each, 2);
this.dataGridView1.Rows[i].Cells[2].Value = decimalcorund.ToString();
}
how to create event in C# banglahelp
- আপনি আপনার প্রোজেক্ট প্রোপার্টিজ মেনু থেকে এভেন্ট এ ক্লিক করুন তারপর
- আপনি আপনার method এর নাম লিখুন সুবিধা জনক নিয়ম হচ্ছে প্রথম শব্দ সব সময় বড় হাতের অক্ষর হবে । যেমন আমি লেখতে চায় keypress তখন আমার textbox এর নাম অনুযায়ী হবে - textbox_KeyPress আপনাকে কে এভেন্ট প্রোপার্টজ এ KeyPress Type করতে হবে ।
- তাহলে textbox_KeyPress(object sender,eventargs e) নামের একটি method তৈরী হবে । এই ভাবে আপনি common event handing method ছাড়াও আর অনেক মেথড তৈরি করতে পারেন ।
Important Web Site Link For a Programmer
How Enter key will work like tab key
if (e.KeyChar == (char)13){SendKeys.Send("{tab}");}
private void txtagentname_KeyPress(object sender, KeyPressEventArgs e){if (e.KeyChar == (char)13){SendKeys.Send("{tab}");}}