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.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace WebApplication3
{
/// <summary>
/// Summary description for DataForm1.
/// </summary>
public class DataForm1 : System.Web.UI.Page
{
protected WebApplication3.ds objds;
protected System.Web.UI.WebControls.Button buttonLoad;
protected System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
public System.Data.SqlClient.SqlConnection myConnection;
protected System.Data.SqlClient.SqlCommand sqlSelectCommand1;
protected System.Data.SqlClient.SqlCommand sqlInsertCommand1;
protected System.Data.SqlClient.SqlCommand sqlUpdateCommand1;
protected System.Data.SqlClient.SqlCommand sqlDeleteCommand1;
protected System.Web.UI.WebControls.DataGrid myList;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
System.Data.SqlClient.SqlConnection myConnection = new System.Data.SqlClient.SqlConnection();
System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter();
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.Configuration.AppSettingsReader configurationAppSettings = new System.Configuration.AppSettingsReader();
this.objds = new WebApplication3.ds();
this.sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter();
this.sqlDeleteCommand1 = new System.Data.SqlClient.SqlCommand();
this.myConnection = new System.Data.SqlClient.SqlConnection();
this.sqlInsertCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlUpdateCommand1 = new System.Data.SqlClient.SqlCommand();
((System.ComponentModel.ISupportInitialize)(this.o bjds)).BeginInit();
this.buttonLoad.Click += new System.EventHandler(this.buttonLoad_Click);
this.myList.SelectedIndexChanged += new System.EventHandler(this.masterDataGrid_SelectedIn dexChanged);
//
// objds
//
this.objds.DataSetName = "ds";
this.objds.Locale = new System.Globalization.CultureInfo("en-US");
this.objds.Namespace = "http://www.tempuri.org/ds.xsd";
//
// sqlDataAdapter1
//
this.sqlDataAdapter1.DeleteCommand = this.sqlDeleteCommand1;
this.sqlDataAdapter1.InsertCommand = this.sqlInsertCommand1;
this.sqlDataAdapter1.SelectCommand = this.sqlSelectCommand1;
this.sqlDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table", "Course", new System.Data.Common.DataColumnMapping[] {
new System.Data.Common.DataColumnMapping("CourseID", "CourseID"),
new System.Data.Common.DataColumnMapping("CourseName", "CourseName"),
new System.Data.Common.DataColumnMapping("CourseDescri ption", "CourseDescription"),
new System.Data.Common.DataColumnMapping("Activate", "Activate")})});
this.sqlDataAdapter1.UpdateCommand = this.sqlUpdateCommand1;
//
// sqlDeleteCommand1
//
this.sqlDeleteCommand1.CommandText = @"DELETE FROM Course WHERE (CourseID = @Original_CourseID) AND (Activate = @Original_Activate OR @Original_Activate IS NULL AND Activate IS NULL) AND (CourseDescription = @Original_CourseDescription OR @Original_CourseDescription IS NULL AND CourseDescription IS NULL) AND (CourseName = @Original_CourseName)";
this.sqlDeleteCommand1.Connection = this.myConnection;
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Cour seID", System.Data.SqlDbType.Decimal, 9, System.Data.ParameterDirection.Input, false, ((System.Byte)(18)), ((System.Byte)(0)), "CourseID", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Acti vate", System.Data.SqlDbType.Bit, 1, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Activate", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Cour seDescription", System.Data.SqlDbType.VarChar, 255, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "CourseDescription", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Cour seName", System.Data.SqlDbType.VarChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "CourseName", System.Data.DataRowVersion.Original, null));
//
// myConnection
//
this.myConnection.ConnectionString = ((string)(configurationAppSettings.GetValue("myCon nection.ConnectionString", typeof(string))));
//
// sqlInsertCommand1
//
this.sqlInsertCommand1.CommandText = "INSERT INTO Course(CourseName, CourseDescription, Activate) VALUES (@CourseName, " +
"@CourseDescription, @Activate); SELECT CourseID, CourseName, CourseDescription, " +
"Activate FROM Course WHERE (CourseID = @@IDENTITY)";
this.sqlInsertCommand1.Connection = this.myConnection;
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@CourseName", System.Data.SqlDbType.VarChar, 50, "CourseName"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@CourseDescrip tion", System.Data.SqlDbType.VarChar, 255, "CourseDescription"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Activate", System.Data.SqlDbType.Bit, 1, "Activate"));
//
// sqlSelectCommand1
//
this.sqlSelectCommand1.CommandText = "SELECT CourseID, CourseName, CourseDescription, Activate FROM Course";
this.sqlSelectCommand1.Connection = this.myConnection;
//
// sqlUpdateCommand1
//
this.sqlUpdateCommand1.CommandText = @"UPDATE Course SET CourseName = @CourseName, CourseDescription = @CourseDescription, Activate = @Activate WHERE (CourseID = @Original_CourseID) AND (Activate = @Original_Activate OR @Original_Activate IS NULL AND Activate IS NULL) AND (CourseDescription = @Original_CourseDescription OR @Original_CourseDescription IS NULL AND CourseDescription IS NULL) AND (CourseName = @Original_CourseName); SELECT CourseID, CourseName, CourseDescription, Activate FROM Course WHERE (CourseID = @CourseID)";
this.sqlUpdateCommand1.Connection = this.myConnection;
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@CourseName", System.Data.SqlDbType.VarChar, 50, "CourseName"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@CourseDescrip tion", System.Data.SqlDbType.VarChar, 255, "CourseDescription"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Activate", System.Data.SqlDbType.Bit, 1, "Activate"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Cour seID", System.Data.SqlDbType.Decimal, 9, System.Data.ParameterDirection.Input, false, ((System.Byte)(18)), ((System.Byte)(0)), "CourseID", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Acti vate", System.Data.SqlDbType.Bit, 1, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "Activate", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Cour seDescription", System.Data.SqlDbType.VarChar, 255, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "CourseDescription", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_Cour seName", System.Data.SqlDbType.VarChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "CourseName", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@CourseID", System.Data.SqlDbType.Decimal, 9, System.Data.ParameterDirection.Input, false, ((System.Byte)(18)), ((System.Byte)(0)), "CourseID", System.Data.DataRowVersion.Current, null));
this.Load += new System.EventHandler(this.Page_Load);
((System.ComponentModel.ISupportInitialize)(this.o bjds)).EndInit();
}
#endregion
private void buttonLoad_Click(object sender, System.EventArgs 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.DataSource = ds.Tables["Course"].DefaultView;
myList.DataBind();
this.myList.SelectedIndex = -1;
this.myList.DataBind();
}
catch (System.Exception eLoad)
{
this.Response.Write(eLoad.Message);
}
}
private void masterDataGrid_SelectedIndexChanged(object sender, System.EventArgs e)
{
}
}
}
---
Posted using Wimdows.net NntpNews Component -
Post Made from http://www.DotNetJunkies.com/newsgroups Our newsgroup engine supports Post Alerts, Ratings, and Searching.