Man*_*Mar 3 c# textbox stored-procedures datagridview sql-server-2008-r2
我在 SQL Server 中有这个程序:
create procedure AutoSearchTeamByMobile
@Team_Mobile int
As
select * from Team_Info where Team_Mobile like @Team_Mobile+'%';
Run Code Online (Sandbox Code Playgroud)
我在 C# 中有这个代码:
private void textBoxX4_TextChanged(object sender, EventArgs e)
{
int tMobile= int.Parse(textBoxX4.Text);
SqlCommand com = new SqlCommand("AutoSearchTeamByMobile", con);
com.Parameters.Add("@Team_Mobile", SqlDbType.Int).Value = tMobile;
com.CommandType = CommandType.StoredProcedure;
SqlDataAdapter da = new SqlDataAdapter();
DataSet ds = new DataSet();
da.SelectCommand = com;
da.Fill(ds, "Team_Info");
dataGridViewX1.DataSource = ds.Tables["Team_Info"];
}
Run Code Online (Sandbox Code Playgroud)
我有一个手机号码列表,它们保存在Team_Mobile数据类型为 as 的列中int,其中一个以“711......”开头,另一个以“700......”开头,所以现在当我textBoxX4只写“7”,然后所有数字(以 711 或 700 开头)都应该dataGridViewX1出现在dataGridViewX1. 当我写“70”时,只有以 700 开头的数字才会出现在dataGridViewX1. 我没有得到我需要的东西,实际上我没有看到任何与我没有做任何事情相同的事情。
我的需要,当我写 71 时,Team_Mobile 列中所有具有 711 的记录应该仍然出现,另一个数字应该隐藏。
但是我用Team_Names它做了并且它有效,因为数据类型Team_Names是nvarchar,但是Team_Mobile是int。
sql:
create procedure AutoSearchTeam
@Team_Name nvarchar (50)
As
select * from Team_Info where Team_Name like @Team_Name+'%';
Run Code Online (Sandbox Code Playgroud)
C#:
private void textBoxX1_TextChanged(object sender, EventArgs e)
{
string t_name = textBoxX1.Text;
SqlCommand com = new SqlCommand("AutoSearchTeam", con);
com.Parameters.Add("@Team_Name", SqlDbType.NVarChar, 50).Value = t_name;
com.CommandType = CommandType.StoredProcedure;
SqlDataAdapter da = new SqlDataAdapter();
DataSet ds = new DataSet();
da.SelectCommand = com;
da.Fill(ds, "Team_Info");
dataGridViewX1.DataSource = ds.Tables["Team_Info"];
}
Run Code Online (Sandbox Code Playgroud)
我的问题是:有没有%办法用整数替换它?
我可以%用整数替换什么来获得我上面解释的内容?
对不起我的英语。
例如这个
SELECT * FROM Team_Info WHERE Team_Mobile LIKE CAST(@Team_Mobile AS NVARCHAR) + '%';
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
14458 次 |
| 最近记录: |