Friday, 31 August 2012

ASP.NET SQL CONNECTIVITY USING WEB.CONFIG


Enter the following connection string in the web config as shown below 

<connectionStrings>

      <add name="SQLCON" connectionString="Data Source=OFFICE-PC\SQLEXPRESS;Initial            Catalog=databasename;Integrated Security=true;User id=sa;Password=;"/>

</connectionStrings>

Call the above in the aspx.cs page as shown below in the page load or as public

//Use this sql namespace at the starting along with the other namespaces as shown 
Using System.Data.SqlClient

//Calling the Connectionstring

static string strcon = ConfigurationManager.ConnectionStrings["SQLCON"].ConnectionString;
//Create new sqlconnection and connection to database by using connection string from web.config file SqlConnection con = new SqlConnection(strcon);




Friday, 17 August 2012

MESSAGE BOX IN C#


if (MessageBox.Show(”Do you want to delete?”, Confirm delete”,MessageBoxButtons.YesNo) == DialogResult.Yes)

{

MessageBox.Show(”Deleted”);

}

Thursday, 16 August 2012

AGE CALCULATION USING DATE OF BIRTH IN C#

DateTime olddate = Convert.ToDateTime(textBox1.Text);

DateTime newdate = DateTime.Now;

TimeSpan ts = newdate - olddate;

int differenceindays = ts.Days;

int differenceinmonths = (differenceindays / 365);

textBox5.Text = differenceinmonths.ToString();

Tuesday, 14 August 2012

AUTO NUMBER GENERATION

OleDbConnection cn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=..\..\..\database.mdb");

cn.open();

DataSet ds = new DataSet();

OleDbDataAdapter da = new OleDbDataAdapter("SELECT iif(max(fieldname)=Null,1,max(field name) +1) as [Number] from Tablename", cn);

da.Fill(ds);

if (ds.Tables[0].Rows.Count > 0)
{

textBox1.Text= ds.Tables[0].Rows[0]["Number"].ToString();

}

cn.close();

Wednesday, 8 August 2012

RUNTIME ERROR : "object does not contain a definition for get_Range" in MS Excel

 Microsoft.Office.Interop.Excel.Range myrange = excelsheet.get_Range(excelsheet.Cells[1, 1], excelsheet.Cells[this.dataGridView1.RowCount + 1, this.dataGridView1.Columns.Count]);


 Solution:

Include (object) as shown in the below line....................



 Microsoft.Office.Interop.Excel.Range myrange = excelsheet.get_Range((object)excelsheet.Cells[1, 1], (object)excelsheet.Cells[this.dataGridView1.RowCount + 1, this.dataGridView1.Columns.Count]);


back to top