using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data;
using System.Data.SqlClient;
namespace aukcijska_p
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
string username = textBox1.Text;
string password = textBox2.Text;
if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))
MessageBox.Show("Please insert correct values.", "Incorrect Username or password.");
else
{
SqlConnection con = new SqlConnection(@"data source=(local);database=aukcija;integrated security=true;");
con.Open();
SqlCommand cmd = new SqlCommand("Select count(*) from users where name='" + username + "' and password='" + password + "'", con);
Int32 returnedCount = (Int32)cmd.ExecuteScalar();
if (returnedCount > 0)
new Window();
else
MessageBox.Show("Wrong username or password");
}
}
private void textBox1_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e)
{
}
private void textBox2_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e)
{
}
}
この:
<Window x:Class="aukcijska_p.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="227" Width="292">
<Grid Height="196" Width="281">
<Label Content="Username:" Height="28" HorizontalAlignment="Left" Margin="37,63,0,0" Name="label1" VerticalAlignment="Top" Width="75" />
<Label Content="Password:" Height="28" HorizontalAlignment="Left" Margin="37,99,0,0" Name="label2" VerticalAlignment="Top" Width="75" />
<Button Content="Confirm" Height="23" HorizontalAlignment="Left" Margin="157,133,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="112,68,0,0" Name="textBox1" VerticalAlignment="Top" Width="120" TextChanged="textBox1_TextChanged" />
<TextBox Height="23" HorizontalAlignment="Left" Margin="112,101,0,0" Name="textBox2" VerticalAlignment="Top" Width="120" TextChanged="textBox2_TextChanged" Visibility="Visible" />
</Grid>
</Window>
正常にデバッグされますが、確認を押すと、次のメッセージが表示されます。プログラムが動作を停止しました。どこで間違いを犯していますか?誰でも私を助けることができますか?iveはこのテーブルでSQLデータベースを作成しました:ユーザー:user_ID、username、userpassword、user_level
ここに画像があります: http ://www39.zippyshare.com/v/97161315/file.html