اسم فیلدم fn هستش تو سورسی که گذاشتم مشخصه
dv.RowFilter = string.Format("fn Like '{0}%'", name);
در پایین کل سورس را گذاشتم
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace ConnectioinToSql2008
{
public partial class formConnectioinToSql2008 : Form
{
DataView dv;
SqlConnection conn = new SqlConnection();
SqlCommand cmd = new SqlCommand();
//SqlDataReader rd;
SqlDataAdapter da = new SqlDataAdapter();
DataSet ds = new DataSet();
public formConnectioinToSql2008()
{
InitializeComponent();
}
private void formConnectioinToSql2008_Load(object sender, EventArgs e)
{
string str = @"server=Mehran;" + "database=for_work;" + "Integrated Security=True";
conn.ConnectionString = str;
//conn.Open();
cmd.Connection = conn;
cmd.CommandText = @"select * from tinfo";
da.SelectCommand = cmd;
//rd = com.ExecuteReader();
//ds.Clear();
da.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
//rd.Close();
//conn.Close();
} // end method formConnectioinToSql2008_Load
private void addButton_Click(object sender, EventArgs e)
{
//cmd.CommandText = "insert into tinfo(code,fn,ln,jens) valuse ('"
//+ fNTextBox.Text + "','" + lNTextBox.Text + "',";
cmd.CommandText = "insert into tinfo(code,fn,ln,jens) values (@code,@fn,@ln,@jens)";
cmd.Parameters.AddWithValue("@fn", fNTextBox.Text);
cmd.Parameters.AddWithValue("@ln", lNTextBox.Text);
cmd.Parameters.AddWithValue("@code", codeTextBox.Text);
cmd.Parameters.AddWithValue("@jens", jensTextBox.Text);
foreach(Control sayre in this.Controls)
{
if (sayre is TextBox)
(sayre as TextBox).Clear();
}
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
}
private void codeTextBox_KeyPress(object sender, KeyPressEventArgs e)
{
//faghat addad migire
if ((e.KeyChar != 8) && (e.KeyChar != 13))
e.Handled = !char.IsDigit(e.KeyChar);
// hich klidi gheyr az adad ruye keybord karnemikone
//if (e.KeyChar < '0' || e.KeyChar > '9')
// e.Handled = true;
}
private void searchTextBox_TextChanged(object sender, EventArgs e)
{
string name = searchTextBox.Text;
dv.RowFilter = string.Format("fn Like '{0}%'", name);
}
}
}