PDA

View Full Version : ادامه این کدها باید چی بنویسم؟



salehvasaleh
یک شنبه 02 بهمن 1390, 16:32 عصر
دوستان من در فرم لاگینم وقتی کاربر روی دکمه ورود کلیک می کنه در اونها کدهای زیر قرار داره ، هدفم اینه اگه آی دی و پسوردی که در تکست باکسهای یک و دو وارد شد درست بود کاربر وارد فرم اصی بشه در ادامه کدهای زیر باید چی بنویسم؟



string str;
str = "Data Source=.;Initial Catalog=ghalam;Integrated Security=True";
SqlConnection con = new SqlConnection(str);
con.Open();
SqlCommand com = new SqlCommand("select * from ramz where id=@id , password=@password", con);
com.Parameters.AddWithValue("@id", textBox1.Text.Trim());
com.Parameters.AddWithValue("@password", textBox2.Text.Trim());
؟؟؟؟

AliSaeedi_v
یک شنبه 02 بهمن 1390, 16:38 عصر
سلام
dataadapter.fill(datatable);
if (dt.rows.count>0)
frmmain.show();

salehvasaleh
یک شنبه 02 بهمن 1390, 16:44 عصر
سلام
dataadapter.fill(datatable);
if (dt.rows.count>0)
frmmain.show();

سلام ضمن تشکر از این کدتون. راستش چیزی متوجه نشدم و ندونستم دقیقا چطوریه یعنی راهی نیست این کار رو بذون دیتا آداپتر انجام بدم؟؟ کدی دیگه به ذهنتون نمی رسه؟
ممنون

AliSaeedi_v
یک شنبه 02 بهمن 1390, 17:10 عصر
معمولا از این روش استفاده میشه.چون شما داری select میکنی یه جدول برمیگردونه.ما با این کد میگیم اگه تعداد سطرهای جدول بیشتر از صفر بود یه نفر وجود داره.

mp_mp353
یک شنبه 02 بهمن 1390, 17:53 عصر
این کد با سی شارپه مال یکی از برنامه های قدیمیم ببین به دردت میخوره
private void btnenter_Click_1(object sender, EventArgs e)
{
for (int i = 0; i < txtpass.Text.Length; i++)
{
if (txtpass.Text[i]=='\'')
{
MessageBox.Show("توجه در پسورد و شناسه از علائم(',\",.,\\,;,?,@,...) نباید استفاده شود!", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
txtid.Clear();
txtpass.Clear();
txtid.Select();
return;
}
}
for (int i = 0; i < txtid.Text.Length; i++)
{
if (txtid.Text[i] == '\'')
{
MessageBox.Show("توجه در پسورد و شناسه از علائم(',\",.,\\,;,?,@,...) نباید استفاده شود!", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
txtid.Clear();
txtpass.Clear();
txtid.Select();
return;
}
}
OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|HelalDb.mdb;Jet OLEDB:Database Password=12344321;");
//string oledbConnectString ="Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|hdb.accdb;Jet OLEDB:Database Password=12344321;";
con.Open();
string s="select * From users where id='" + txtid.Text + "' and pass='" + txtpass.Text + "'";
OleDbDataAdapter da = new OleDbDataAdapter(s, con);
DataSet ds = new DataSet();
da.Fill(ds, "users");
if (ds.Tables[0].Rows.Count == 0)
{
MessageBox.Show("اطلاعات ورودی اشتباه است لطفا دوباره سعی کنید", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
txtpass.Clear();
txtid.Clear();
txtid.Select();
return;
}
else
{
Program.gp.right = ds.Tables[0].Rows[0][2].ToString();
Program.gp.struser = ds.Tables[0].Rows[0][0].ToString();
m2 = 1;//becuse if this window closed we can understand clicked on close and exit from form or type a true pass and close form to general part
Close();
}
}