własnie nie widze błędów w tym diagramie :/
próbuje to teraz zrobić w trochę inny sposób, a mianowicie poprzez zapytania Lambda, tyle że tu znowu dostaje taki komunikat:
System.Data.EntityCommandExecutionException was unhandled
Message=Wystąpił błąd podczas wykonywania definicji polecenia. Aby uzyskać szczegółowe informacje, zobacz wyjątek wewnętrzny.
Source=System.Data.Entity
StackTrace:
w System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)
w System.Data.Objects.Internal.ObjectQueryExecutionPlan.Execute[TResultType](ObjectContext context, ObjectParameterCollection parameterValues)
w System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)
w System.Data.Objects.ObjectQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator()
w System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source)
w BudSystem.FormLogowanie.czyPrawidloweHaslo(String login, String haslo) w C:\Users\Szymon\Desktop\praca inż\BudSystem\FormLogowanie.cs:wiersz 47
w BudSystem.FormLogowanie.buttonZaloguj_Click(Object sender, EventArgs e) w C:\Users\Szymon\Desktop\praca inż\BudSystem\FormLogowanie.cs:wiersz 23
w System.Windows.Forms.Control.OnClick(EventArgs e)
w System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
w System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
w System.Windows.Forms.Control.WndProc(Message& m)
w System.Windows.Forms.ButtonBase.WndProc(Message& m)
w System.Windows.Forms.Button.WndProc(Message& m)
w System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
w System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
w System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
w System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
w System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
w System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
w BudSystem.Program.Main() w C:\Users\Szymon\Desktop\praca inż\BudSystem\Program.cs:wiersz 19
w System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
w Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
w System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
w System.Threading.ThreadHelper.ThreadStart()
InnerException: System.Data.SqlClient.SqlException
Message=The data types text and nvarchar are incompatible in the equal to operator.
Source=.Net SqlClient Data Provider
ErrorCode=-2146232060
Class=16
LineNumber=6
Number=402
Procedure=""
Server=SZYMON-DELL
State=1
StackTrace:
w System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
w System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
w System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
w System.Data.SqlClient.SqlDataReader.ConsumeMetaData()
w System.Data.SqlClient.SqlDataReader.get_MetaData()
w System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
w System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
w System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
w System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
w System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
w System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
w System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)
InnerException:
a mój kod wygląda nastepująco:
private void buttonZaloguj_Click(object sender, EventArgs e)
{
if (czyPrawidloweHaslo(textBoxLogin.Text, maskedTextBoxHaslo.Text) == true) Application.Run(new FormGlowne());
}
private bool czyPrawidloweHaslo(string login, string haslo)
{
BudSystemEntities bazaBudSystem = new BudSystemEntities();
var uzytkownik = (from uzytkownicy in bazaBudSystem.Uzytkownicy
where (uzytkownicy.login == login) && (uzytkownicy.haslo == haslo)
select new
{
uzytkownicy.login,
uzytkownicy.haslo
}).AsEnumerable().FirstOrDefault();
if (uzytkownik == null) return false;
return true;
}
Debuger od razu podświetla problem z porównywaniem string'ów poprzez "==" w zapytaniu po WHERE, ale jak próbuje z .CompareTo(...) to też nie działa. Kolumny login i hasło w bazie danych są w dalszym ciągu typu nvarchar.