ADO.Net in C#

Results 1 to 2 of 2

Thread: ADO.Net in C#

  1. #1
    Join Date
    Dec 1969

    Default ADO.Net in C#

    hi,<BR>can anyone of u tell me whether i am using correct code to connect to database using c#.<BR><BR>using System;<BR>using System.Collections;<BR>using System.ComponentModel;<BR>using System.Data;<BR>using System.Data.SqlClient; <BR>using System.Drawing;<BR>using System.Web;<BR>using System.Web.SessionState;<BR>using System.Web.UI;<BR>using System.Web.UI.WebControls;<BR>using System.Web.UI.HtmlControls;<BR><BR>namespace WebApplication1<BR>{<BR> /// &#060;summary&#062;<BR> /// Summary description for simpledatac.<BR> /// &#060;/summary&#062;<BR> public class simpledatac : System.Web.UI.Page<BR> {<BR> protected System.Web.UI.WebControls.DataGrid DataGrid1;<BR> protected System.Web.UI.WebControls.DataGrid DG1;<BR> <BR> private void Page_Load(object sender, System.EventArgs e)<BR> {<BR> // Put user code to initialize the page here<BR> <BR> }<BR><BR> #region Web Form Designer generated code<BR> override protected void OnInit(EventArgs e)<BR> {<BR> //<BR> // CODEGEN: This call is required by the ASP.NET Web Form Designer.<BR> //<BR> InitializeComponent();<BR> base.OnInit(e);<BR><BR> }<BR> <BR> /// &#060;summary&#062;<BR> /// Required method for Designer support - do not modify<BR> /// the contents of this method with the code editor.<BR> /// &#060;/summary&#062;<BR> private void InitializeComponent()<BR> { <BR> this.Load += new System.EventHandler(this.Page_Load);<BR> DataSet ds = new DataSet(); <BR> <BR>// strconn = "server=(local)
    etsdk;database=pubs;trusted_connection=yes";<BR> SqlConnection conn = new SqlConnection("server=(local)
    etsdk;database=pubs;trusted_connection=yes");<BR> <BR> SqlDataAdapter invadap = new SqlDataAdapter("select * from bomlnkdtl",conn);<BR> invadap.Fill(ds,"bomlnkdtl");<BR> <BR> DG1.DataSource = ds;<BR> DG1.DataBind();<BR><BR> }<BR> #endregion<BR> }<BR>}<BR><BR>because it gives the error like this,<BR><BR>sql server does not exist or access denied<BR><BR><BR>advance thankx ,<BR>bye<BR>ulaga<BR><BR><BR>

  2. #2
    Join Date
    Dec 1969

    Default The code is fine..

    .. but your connection string could be wrong.<BR><BR>Take a look at for a connection string for SQL Server.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts