I am a beginner and trying my first C# application.
Any reason why I am getting the message Login failed for user 'admin'
I have thoroughly checked the security settings in the sql server.
Find my code below.
using System;
using System.Collecti ons;
using System.Componen tModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.Sess ionState;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.H tmlControls;
namespace WebApplication3
{
/// <summary>
/// Summary description for DataForm1.
/// </summary>
public class DataForm1 : System.Web.UI.P age
{
protected WebApplication3 .ds objds;
protected System.Web.UI.W ebControls.Butt on buttonLoad;
protected System.Data.Sql Client.SqlDataA dapter sqlDataAdapter1 ;
public System.Data.Sql Client.SqlConne ction myConnection;
protected System.Data.Sql Client.SqlComma nd sqlSelectComman d1;
protected System.Data.Sql Client.SqlComma nd sqlInsertComman d1;
protected System.Data.Sql Client.SqlComma nd sqlUpdateComman d1;
protected System.Data.Sql Client.SqlComma nd sqlDeleteComman d1;
protected System.Web.UI.W ebControls.Data Grid myList;
private void Page_Load(objec t sender, System.EventArg s e)
{
// Put user code to initialize the page here
System.Data.Sql Client.SqlConne ction myConnection = new System.Data.Sql Client.SqlConne ction();
System.Data.Sql Client.SqlDataA dapter sqlDataAdapter1 = new System.Data.Sql Client.SqlDataA dapter();
}
#region Web Form Designer generated code
override protected void OnInit(EventArg s e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeCompo nent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeCompo nent()
{
System.Configur ation.AppSettin gsReader configurationAp pSettings = new System.Configur ation.AppSettin gsReader();
this.objds = new WebApplication3 .ds();
this.sqlDataAda pter1 = new System.Data.Sql Client.SqlDataA dapter();
this.sqlDeleteC ommand1 = new System.Data.Sql Client.SqlComma nd();
this.myConnecti on = new System.Data.Sql Client.SqlConne ction();
this.sqlInsertC ommand1 = new System.Data.Sql Client.SqlComma nd();
this.sqlSelectC ommand1 = new System.Data.Sql Client.SqlComma nd();
this.sqlUpdateC ommand1 = new System.Data.Sql Client.SqlComma nd();
((System.Compon entModel.ISuppo rtInitialize)(t his.objds)).Beg inInit();
this.buttonLoad .Click += new System.EventHan dler(this.butto nLoad_Click);
this.myList.Sel ectedIndexChang ed += new System.EventHan dler(this.maste rDataGrid_Selec tedIndexChanged );
//
// objds
//
this.objds.Data SetName = "ds";
this.objds.Loca le = new System.Globaliz ation.CultureIn fo("en-US");
this.objds.Name space = "http://www.tempuri.org/ds.xsd";
//
// sqlDataAdapter1
//
this.sqlDataAda pter1.DeleteCom mand = this.sqlDeleteC ommand1;
this.sqlDataAda pter1.InsertCom mand = this.sqlInsertC ommand1;
this.sqlDataAda pter1.SelectCom mand = this.sqlSelectC ommand1;
this.sqlDataAda pter1.TableMapp ings.AddRange(n ew System.Data.Com mon.DataTableMa pping[] {
new System.Data.Com mon.DataTableMa pping("Table", "Course", new System.Data.Com mon.DataColumnM apping[] {
new System.Data.Com mon.DataColumnM apping("CourseI D", "CourseID") ,
new System.Data.Com mon.DataColumnM apping("CourseN ame", "CourseName "),
new System.Data.Com mon.DataColumnM apping("CourseD escription", "CourseDescript ion"),
new System.Data.Com mon.DataColumnM apping("Activat e", "Activate")})}) ;
this.sqlDataAda pter1.UpdateCom mand = this.sqlUpdateC ommand1;
//
// sqlDeleteComman d1
//
this.sqlDeleteC ommand1.Command Text = @"DELETE FROM Course WHERE (CourseID = @Original_Cours eID) AND (Activate = @Original_Activ ate OR @Original_Activ ate IS NULL AND Activate IS NULL) AND (CourseDescript ion = @Original_Cours eDescription OR @Original_Cours eDescription IS NULL AND CourseDescripti on IS NULL) AND (CourseName = @Original_Cours eName)";
this.sqlDeleteC ommand1.Connect ion = this.myConnecti on;
this.sqlDeleteC ommand1.Paramet ers.Add(new System.Data.Sql Client.SqlParam eter("@Original _CourseID", System.Data.Sql DbType.Decimal, 9, System.Data.Par ameterDirection .Input, false, ((System.Byte)( 18)), ((System.Byte)( 0)), "CourseID", System.Data.Dat aRowVersion.Ori ginal, null));
this.sqlDeleteC ommand1.Paramet ers.Add(new System.Data.Sql Client.SqlParam eter("@Original _Activate", System.Data.Sql DbType.Bit, 1, System.Data.Par ameterDirection .Input, false, ((System.Byte)( 0)), ((System.Byte)( 0)), "Activate", System.Data.Dat aRowVersion.Ori ginal, null));
this.sqlDeleteC ommand1.Paramet ers.Add(new System.Data.Sql Client.SqlParam eter("@Original _CourseDescript ion", System.Data.Sql DbType.VarChar, 255, System.Data.Par ameterDirection .Input, false, ((System.Byte)( 0)), ((System.Byte)( 0)), "CourseDescript ion", System.Data.Dat aRowVersion.Ori ginal, null));
this.sqlDeleteC ommand1.Paramet ers.Add(new System.Data.Sql Client.SqlParam eter("@Original _CourseName", System.Data.Sql DbType.VarChar, 50, System.Data.Par ameterDirection .Input, false, ((System.Byte)( 0)), ((System.Byte)( 0)), "CourseName ", System.Data.Dat aRowVersion.Ori ginal, null));
//
// myConnection
//
this.myConnecti on.ConnectionSt ring = ((string)(confi gurationAppSett ings.GetValue(" myConnection.Co nnectionString" , typeof(string)) ));
//
// sqlInsertComman d1
//
this.sqlInsertC ommand1.Command Text = "INSERT INTO Course(CourseNa me, CourseDescripti on, Activate) VALUES (@CourseName, " +
"@CourseDescrip tion, @Activate); SELECT CourseID, CourseName, CourseDescripti on, " +
"Activate FROM Course WHERE (CourseID = @@IDENTITY)";
this.sqlInsertC ommand1.Connect ion = this.myConnecti on;
this.sqlInsertC ommand1.Paramet ers.Add(new System.Data.Sql Client.SqlParam eter("@CourseNa me", System.Data.Sql DbType.VarChar, 50, "CourseName "));
this.sqlInsertC ommand1.Paramet ers.Add(new System.Data.Sql Client.SqlParam eter("@CourseDe scription", System.Data.Sql DbType.VarChar, 255, "CourseDescript ion"));
this.sqlInsertC ommand1.Paramet ers.Add(new System.Data.Sql Client.SqlParam eter("@Activate ", System.Data.Sql DbType.Bit, 1, "Activate") );
//
// sqlSelectComman d1
//
this.sqlSelectC ommand1.Command Text = "SELECT CourseID, CourseName, CourseDescripti on, Activate FROM Course";
this.sqlSelectC ommand1.Connect ion = this.myConnecti on;
//
// sqlUpdateComman d1
//
this.sqlUpdateC ommand1.Command Text = @"UPDATE Course SET CourseName = @CourseName, CourseDescripti on = @CourseDescript ion, Activate = @Activate WHERE (CourseID = @Original_Cours eID) AND (Activate = @Original_Activ ate OR @Original_Activ ate IS NULL AND Activate IS NULL) AND (CourseDescript ion = @Original_Cours eDescription OR @Original_Cours eDescription IS NULL AND CourseDescripti on IS NULL) AND (CourseName = @Original_Cours eName); SELECT CourseID, CourseName, CourseDescripti on, Activate FROM Course WHERE (CourseID = @CourseID)";
this.sqlUpdateC ommand1.Connect ion = this.myConnecti on;
this.sqlUpdateC ommand1.Paramet ers.Add(new System.Data.Sql Client.SqlParam eter("@CourseNa me", System.Data.Sql DbType.VarChar, 50, "CourseName "));
this.sqlUpdateC ommand1.Paramet ers.Add(new System.Data.Sql Client.SqlParam eter("@CourseDe scription", System.Data.Sql DbType.VarChar, 255, "CourseDescript ion"));
this.sqlUpdateC ommand1.Paramet ers.Add(new System.Data.Sql Client.SqlParam eter("@Activate ", System.Data.Sql DbType.Bit, 1, "Activate") );
this.sqlUpdateC ommand1.Paramet ers.Add(new System.Data.Sql Client.SqlParam eter("@Original _CourseID", System.Data.Sql DbType.Decimal, 9, System.Data.Par ameterDirection .Input, false, ((System.Byte)( 18)), ((System.Byte)( 0)), "CourseID", System.Data.Dat aRowVersion.Ori ginal, null));
this.sqlUpdateC ommand1.Paramet ers.Add(new System.Data.Sql Client.SqlParam eter("@Original _Activate", System.Data.Sql DbType.Bit, 1, System.Data.Par ameterDirection .Input, false, ((System.Byte)( 0)), ((System.Byte)( 0)), "Activate", System.Data.Dat aRowVersion.Ori ginal, null));
this.sqlUpdateC ommand1.Paramet ers.Add(new System.Data.Sql Client.SqlParam eter("@Original _CourseDescript ion", System.Data.Sql DbType.VarChar, 255, System.Data.Par ameterDirection .Input, false, ((System.Byte)( 0)), ((System.Byte)( 0)), "CourseDescript ion", System.Data.Dat aRowVersion.Ori ginal, null));
this.sqlUpdateC ommand1.Paramet ers.Add(new System.Data.Sql Client.SqlParam eter("@Original _CourseName", System.Data.Sql DbType.VarChar, 50, System.Data.Par ameterDirection .Input, false, ((System.Byte)( 0)), ((System.Byte)( 0)), "CourseName ", System.Data.Dat aRowVersion.Ori ginal, null));
this.sqlUpdateC ommand1.Paramet ers.Add(new System.Data.Sql Client.SqlParam eter("@CourseID ", System.Data.Sql DbType.Decimal, 9, System.Data.Par ameterDirection .Input, false, ((System.Byte)( 18)), ((System.Byte)( 0)), "CourseID", System.Data.Dat aRowVersion.Cur rent, null));
this.Load += new System.EventHan dler(this.Page_ Load);
((System.Compon entModel.ISuppo rtInitialize)(t his.objds)).End Init();
}
#endregion
private void buttonLoad_Clic k(object sender, System.EventArg s e)
{
try
{
// Place code here to fill the dataset. The grid will not render in the page if the dataset is empty.
DataSet ds = new DataSet();
sqlDataAdapter1 .Fill(ds, "Course");
myList.DataSour ce = ds.Tables["Course"].DefaultView;
myList.DataBind ();
this.myList.Sel ectedIndex = -1;
this.myList.Dat aBind();
}
catch (System.Excepti on eLoad)
{
this.Response.W rite(eLoad.Mess age);
}
}
private void masterDataGrid_ SelectedIndexCh anged(object sender, System.EventArg s e)
{
}
}
}
---
Posted using Wimdows.net NntpNews Component -
Post Made from http://www.DotNetJunkies.com/newsgroups Our newsgroup engine supports Post Alerts, Ratings, and Searching.