PDA

View Full Version : سوال: مشکل در درج و جستجو



ahmad_ir
جمعه 25 تیر 1389, 01:06 صبح
سلام
من یه مشکلی داشتم اونم اینه که وقتی از روش پارامتریک برای درج در پایگاه استفاده می کنم
عمل جستجوی من کار نمیکنه یعنی اون اسم رو که درج کردم(پارامتریک) پیدا نمی کنه ولی زمانی که از روش معمولی استفاده کنم عمل جستجو درست کار می کنه و اون اسمی که با این روش درج کردم پیدا می کنه. چون عکس هم ذخیره می کنم تو پایگاه مجبورم از روش پارامتریک استفاده کنم
ممنون میشم کمکم کنید

imani1983
جمعه 25 تیر 1389, 01:33 صبح
شما براي درج از اين نمونه كد استفاده كنيد



private void button1_Click(object sender, EventArgs e)
{

DialogResult dialog = FMessageBox.Show(" آیااز ثبت کالا مطمئن هستيد؟ ", "ثبت کالا به انبار", FMessageBoxButtons.YesNo, FMessageBoxIcons.Question);
if (dialog == DialogResult.Yes)
{
con.Open();
string strsql = "insert into Kala (CodeFactor,codekala,namekala,mojode,tedad,varnume ric,XaridAz,contry,company,varkala,minmojodi,maxmo jodi,datainput,codeanbar,status,vahedanbar,dataxar id,valueXarid,valueFrosh,tedadmayob,bargashti,kala mande,sum_value)VALUES(@CodeFactor,@codekala,@name kala,@mojode,@tedad,@varnumeric,@XaridAz,@contry,@ company,@varkala,@minmojodi,@maxmojodi,@datainput, @codeanbar,@status,@vahedanbar,@dataxarid,@valueXa rid,@valueFrosh,@tedadmayob,@bargashti,@kalamande, @sum_value)";
cmd.Parameters.Clear();
cmd.Parameters.AddWithValue("@CodeFactor", textBox5.Text);
cmd.Parameters.AddWithValue("@codekala", comboBox8.Text);
cmd.Parameters.AddWithValue("@namekala", comboBox7.Text);
cmd.Parameters.AddWithValue("@mojode", textBox3.Text);
cmd.Parameters.AddWithValue("@tedad", textBox4.Text);
cmd.Parameters.AddWithValue("@varnumeric", comboBox5.Text);
cmd.Parameters.AddWithValue("@XaridAz", comboBox2.Text);
cmd.Parameters.AddWithValue("@contry", comboBox3.Text);
cmd.Parameters.AddWithValue("@company", comboBox1.Text);
cmd.Parameters.AddWithValue("@varkala", comboBox6.Text);
cmd.Parameters.AddWithValue("@minmojodi", textBox6.Text);
cmd.Parameters.AddWithValue("@maxmojodi", textBox7.Text);
cmd.Parameters.AddWithValue("@datainput", maskedTextBox2.Text);
cmd.Parameters.AddWithValue("@codeanbar", textBox8.Text);
cmd.Parameters.AddWithValue("@status", comboBox4.Text);
cmd.Parameters.AddWithValue("@vahedanbar", comboBox9.Text);
cmd.Parameters.AddWithValue("@dataxarid", maskedTextBox1.Text);
cmd.Parameters.AddWithValue("@valueXarid", textBox10.Text);
cmd.Parameters.AddWithValue("@valueFrosh", textBox11.Text);
cmd.Parameters.AddWithValue("@tedadmayob", textBox12.Text);
cmd.Parameters.AddWithValue("@bargashti", textBox13.Text);
cmd.Parameters.AddWithValue("@kalamande", textBox14.Text);
cmd.Parameters.AddWithValue("@sum_value", textBox2.Text);
cmd.CommandText = strsql;
int test = cmd.ExecuteNonQuery();
if (test == 1)
{
da.SelectCommand.CommandText = "select *from kala";
da.Fill(ds, "kala");
dataGridView1.DataSource = ds.Tables["kala"];
MessageBox.Show("کالا با موفقیت اضافه شد", "پیام", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.toolStripProgressBar1.Visible = true;
DialogResult dialog1 = FMessageBox.Show("آيا قصد داريد كالاي ديگري را به فاكتور اضافه كنيد؟", "ورود کالا به فاكتور", FMessageBoxButtons.YesNo, FMessageBoxIcons.Question);
if (dialog1 == DialogResult.Yes)
{
comboBox8.Focus();
}
else
{
textBox15.Focus();
}
}
else
{
FMessageBox.Show("كالا اظافه نشد!", "پیام", FMessageBoxButtons.OK, FMessageBoxIcons.Information);
}
}
con.Close();
}
و براي جستجو از اين كد

private void button1_Click(object sender, EventArgs e)
{
try
{
SqlDataAdapter da = new SqlDataAdapter(sqlCommand1.CommandText, sqlConnection1.ConnectionString);
DataSet ds = new DataSet();
SqlDataReader reader;
da.Fill(ds, "customer_tb");
dataGridView1.DataSource = ds;
dataGridView1.DataMember = "customer_tb";
sqlCommand1.Connection.Close();
sqlCommand1.CommandText = "select * from customer_tb where name=" + "'" + textBox1.Text + "'" + "and custno=" + "'" + textBox3.Text + "'" + "and family=" + "'" + textBox2.Text + "'" + "and shsh=" + "'" + textBox4.Text + "'";
sqlCommand1.Connection.Open();

reader = sqlCommand1.ExecuteReader();
while (reader.Read() == true)
{
MaskEdit1.Text = (string)reader["datacreate"];
MaskEdit2.Text = (string)reader["databirth"];
textBox5.Text = (string)reader["telhome"];
textBox6.Text = (string)reader["mobile"];
textBox7.Text = (string)reader["codemelli"];
textBox8.Text = (string)reader["address"];
comboBox5.Text = (string)reader["city"];
comboBox6.Text = (string)reader["shoghl"];
break;
}
}
catch (Exception)
{
MessageBox.Show("چنين کالایی وجود ندارد");
}
}
اميدوارم كه مفيد واقع بشه.

ahmad_ir
شنبه 26 تیر 1389, 09:35 صبح
شما براي درج از اين نمونه كد استفاده كنيد



private void button1_Click(object sender, EventArgs e)
{

DialogResult dialog = FMessageBox.Show(" آیااز ثبت کالا مطمئن هستيد؟ ", "ثبت کالا به انبار", FMessageBoxButtons.YesNo, FMessageBoxIcons.Question);
if (dialog == DialogResult.Yes)
{
con.Open();
string strsql = "insert into Kala (CodeFactor,codekala,namekala,mojode,tedad,varnume ric,XaridAz,contry,company,varkala,minmojodi,maxmo jodi,datainput,codeanbar,status,vahedanbar,dataxar id,valueXarid,valueFrosh,tedadmayob,bargashti,kala mande,sum_value)VALUES(@CodeFactor,@codekala,@name kala,@mojode,@tedad,@varnumeric,@XaridAz,@contry,@ company,@varkala,@minmojodi,@maxmojodi,@datainput, @codeanbar,@status,@vahedanbar,@dataxarid,@valueXa rid,@valueFrosh,@tedadmayob,@bargashti,@kalamande, @sum_value)";
cmd.Parameters.Clear();
cmd.Parameters.AddWithValue("@CodeFactor", textBox5.Text);
cmd.Parameters.AddWithValue("@codekala", comboBox8.Text);
cmd.Parameters.AddWithValue("@namekala", comboBox7.Text);
cmd.Parameters.AddWithValue("@mojode", textBox3.Text);
cmd.Parameters.AddWithValue("@tedad", textBox4.Text);
cmd.Parameters.AddWithValue("@varnumeric", comboBox5.Text);
cmd.Parameters.AddWithValue("@XaridAz", comboBox2.Text);
cmd.Parameters.AddWithValue("@contry", comboBox3.Text);
cmd.Parameters.AddWithValue("@company", comboBox1.Text);
cmd.Parameters.AddWithValue("@varkala", comboBox6.Text);
cmd.Parameters.AddWithValue("@minmojodi", textBox6.Text);
cmd.Parameters.AddWithValue("@maxmojodi", textBox7.Text);
cmd.Parameters.AddWithValue("@datainput", maskedTextBox2.Text);
cmd.Parameters.AddWithValue("@codeanbar", textBox8.Text);
cmd.Parameters.AddWithValue("@status", comboBox4.Text);
cmd.Parameters.AddWithValue("@vahedanbar", comboBox9.Text);
cmd.Parameters.AddWithValue("@dataxarid", maskedTextBox1.Text);
cmd.Parameters.AddWithValue("@valueXarid", textBox10.Text);
cmd.Parameters.AddWithValue("@valueFrosh", textBox11.Text);
cmd.Parameters.AddWithValue("@tedadmayob", textBox12.Text);
cmd.Parameters.AddWithValue("@bargashti", textBox13.Text);
cmd.Parameters.AddWithValue("@kalamande", textBox14.Text);
cmd.Parameters.AddWithValue("@sum_value", textBox2.Text);
cmd.CommandText = strsql;
int test = cmd.ExecuteNonQuery();
if (test == 1)
{
da.SelectCommand.CommandText = "select *from kala";
da.Fill(ds, "kala");
dataGridView1.DataSource = ds.Tables["kala"];
MessageBox.Show("کالا با موفقیت اضافه شد", "پیام", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.toolStripProgressBar1.Visible = true;
DialogResult dialog1 = FMessageBox.Show("آيا قصد داريد كالاي ديگري را به فاكتور اضافه كنيد؟", "ورود کالا به فاكتور", FMessageBoxButtons.YesNo, FMessageBoxIcons.Question);
if (dialog1 == DialogResult.Yes)
{
comboBox8.Focus();
}
else
{
textBox15.Focus();
}
}
else
{
FMessageBox.Show("كالا اظافه نشد!", "پیام", FMessageBoxButtons.OK, FMessageBoxIcons.Information);
}
}
con.Close();
}
و براي جستجو از اين كد

private void button1_Click(object sender, EventArgs e)
{
try
{
SqlDataAdapter da = new SqlDataAdapter(sqlCommand1.CommandText, sqlConnection1.ConnectionString);
DataSet ds = new DataSet();
SqlDataReader reader;
da.Fill(ds, "customer_tb");
dataGridView1.DataSource = ds;
dataGridView1.DataMember = "customer_tb";
sqlCommand1.Connection.Close();
sqlCommand1.CommandText = "select * from customer_tb where name=" + "'" + textBox1.Text + "'" + "and custno=" + "'" + textBox3.Text + "'" + "and family=" + "'" + textBox2.Text + "'" + "and shsh=" + "'" + textBox4.Text + "'";
sqlCommand1.Connection.Open();

reader = sqlCommand1.ExecuteReader();
while (reader.Read() == true)
{
MaskEdit1.Text = (string)reader["datacreate"];
MaskEdit2.Text = (string)reader["databirth"];
textBox5.Text = (string)reader["telhome"];
textBox6.Text = (string)reader["mobile"];
textBox7.Text = (string)reader["codemelli"];
textBox8.Text = (string)reader["address"];
comboBox5.Text = (string)reader["city"];
comboBox6.Text = (string)reader["shoghl"];
break;
}
}
catch (Exception)
{
MessageBox.Show("چنين کالایی وجود ندارد");
}
}
اميدوارم كه مفيد واقع بشه.

سلام دوست عزیز
از کمکتون خیلی ممنونم
ولی مشکلی من اینه برنامم با حروف فارسی مشکل داره با همه حروف فارسی .
وقتی رکوردی که به زبان english هست دستور جستجوی خودم وشما درست کار می کنه ولی وقتی به زبان فارسی باشه کار نمی کنه
واقعا به مشکل خوردم اگه کسی می تونه کمکم کنه