Merhaba arkadaşlar bu makalemizde sql veritabanında kullanıcı
sorgulaması yapacağız. Eğer kullanıcı
veritabanında kayıtlı ise, kayıtlı kullanıcı ile ilgili detayları Listbox
nesnelerinde göstereceğiz.
Sekil 1
Form1.aspx
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
namespace sql_searching_textbox
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
string username, pwd;
private void txtUser_Click(object sender, EventArgs e)
{
txtUser.Text = string.Empty;
}
private void txtPassword_Click(object sender, EventArgs
e)
{
txtPassword.Text = string.Empty;
}
private void btnSearch_Click(object sender, EventArgs e)
{
try
{
listBox1.Items.Clear();
listBox2.Items.Clear();
SqlConnection con = new SqlConnection("Data Source=SIRIUS;Initial Catalog=aus;User
ID=sa;Password=2344;Integrated Security=true");
con.Open();
SqlCommand cmd = new SqlCommand("SELECT Id,username,pwd,name from dbo.users
where username like '%" + txtUser.Text + "%' and pwd='" +
txtPassword.Text + "'", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
SqlDataReader data = cmd.ExecuteReader();
while (data.Read())
{
listBox1.Items.Add(data[0]);
listBox2.Items.Add(data[3]);
username=
data[1].ToString();
pwd = data[2].ToString();
}
if (txtUser.Text == ""
|| txtPassword.Text == "")
{
MessageBox.Show("
Kullanıcı adı veya şifre girmediniz"
+ (char)13
+ "Lütfen tekrar deneyiniz!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (txtUser.Text != username
&& txtPassword.Text != pwd)
{
MessageBox.Show(txtUser.Text
+ " adlı kullanıcı kayıdı bulunamadı!" + (char)13 + "Lütfen
tekrar deneyiniz!", "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
con.Close();
}
catch (Exception err)
{
MessageBox.Show("Hata oluştu! Tekrar deneyiniz!" + (char)13 + "Hata
Kodu : " + err.Message, "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
Bir
makalenin daha sonuna geldik. Bir sonraki makalede gorusmek uzere. Bahadir SAHIN

1 comments:
Customers can use Big Daddy Game to explore cricket id details, sports betting guidance, casino game information, and account access support. The big daddy login link helps users review deposit guidance, withdrawal-related information, and login access in a clear manner. Its straightforward layout supports users who prefer simple instructions. Anyone looking for cricket id access and useful gaming updates can visit big daddy game login for direct navigation.
Yorum Gönder