Connectivity Code For Sql server database in asp.net
A) First Create Database and Table Like UserTable and Table field like UserName,UserPwd,UserMobile,UserEmailId etc.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
usingSystem.Web.UI.WebControls;
using System.Data;
usingSystem.Data.SqlClient;
public partial class PgConnect : System.Web.UI.Page
{
protected void Button1_Click(objectsender, EventArgs e)
{
SqlConnectioncon = new SqlConnection(@"Data Source=.\Syscomservice;Initial Catalog=MyEveData;Integrated Security=True");
//Note: Data Source mein .\ aye to Data Source ke pahle @ Add karte hai
con.Open();
string strInsert = "Insert into USerTable(USerName,USerPwd,UserMobile,UserEmailId) values('Nitin','Joshi',9977298129,'nj@gmail.com')";
Response.Write(strInsert);
SqlCommandcmd = new SqlCommand(strInsert,con );
int x = cmd.ExecuteNonQuery();
con.Close();
Label1.Text = "Rows Inserted =" + x;
}
}
Comments
Post a Comment