cjbaird

cjbaird

  • NA
  • 4
  • 0

Help!... This is driving me nuts - dataset error

Mar 3 2004 4:36 PM
I have been workind on some tutorials that have the code written in vb.net. I'm trying to get it to work in C#. Here is the code and I have indicated the point of the error in the loginbtn_clikd method. I have searched the net for examples and can find none. Please help me if you can spot the error. void LoginBtn_Click(Object sender, EventArgs e) { if (Page.IsValid) { System.Data.DataSet userDS = GetUser(UserName.Text, UserPass.Text) ; ** the error happens here with the debugger saying that "(" is expected. if userDS.Tables(0).Rows.Count = 1 { FormsAuthentication.RedirectFromLoginPage(UserName.Text, true); } else { Msg.Text = "Invalid Credentials: Please try again"; } } } System.Data.DataSet GetUser(string userName, string userPassword) { string connectionString = "server=\'(local)\'; user id=\'sa\'; password=\'\'; database=\'Orders\'"; System.Data.IDbConnection dbConnection = new System.Data.SqlClient.SqlConnection(connectionString); string queryString = "SELECT [Users].* FROM [Users] WHERE (([Users].[UserName] = @UserName) AND ([Users" + "].[UserPassword] = @UserPassword))"; System.Data.IDbCommand dbCommand = new System.Data.SqlClient.SqlCommand(); dbCommand.CommandText = queryString; dbCommand.Connection = dbConnection; System.Data.IDataParameter dbParam_userName = new System.Data.SqlClient.SqlParameter(); dbParam_userName.ParameterName = "@UserName"; dbParam_userName.Value = userName; dbParam_userName.DbType = System.Data.DbType.String; dbCommand.Parameters.Add(dbParam_userName); System.Data.IDataParameter dbParam_userPassword = new System.Data.SqlClient.SqlParameter(); dbParam_userPassword.ParameterName = "@UserPassword"; dbParam_userPassword.Value = userPassword; dbParam_userPassword.DbType = System.Data.DbType.String; dbCommand.Parameters.Add(dbParam_userPassword); System.Data.IDbDataAdapter dataAdapter = new System.Data.SqlClient.SqlDataAdapter(); dataAdapter.SelectCommand = dbCommand; System.Data.DataSet dataSet = new System.Data.DataSet(); dataAdapter.Fill(dataSet); return dataSet;

Answers (3)