从数据集中删除数字 [英] Remove numbers from dataset
本文介绍了从数据集中删除数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
string strConn = ConfigurationManager.ConnectionStrings [ 构造跨度>]的ConnectionString。
SqlConnection con = new SqlConnection(strConn);
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.CommandText = 选择intschoolcode,来自tblSchool_Master的varschoolname,其中varclustercode =' + areaid .ToString()+ ';
DataSet objDs = new DataSet();
SqlDataAdapter dAdapter = new SqlDataAdapter();
dAdapter.SelectCommand = cmd;
con.Open();
dAdapter.Fill(objDs);
con.Close();
if (objDs.Tables [ 0 ]。Rows.Count > 0 )
{
ddlschool.DataSource = objDs.Tables [ 0 跨度>];
ddlschool.DataTextField = varschoolname;
ddlschool.DataValueField = intschoolcode;
ddlschool.DataBind();
ddlschool.Items.Insert( 0 , - 选择 - 跨度>);
}
其他
{
}
这里我想从数据库中的varschoolname数据中删除数字。我该怎么做?
解决方案
您也可以尝试使用Regex。
通过DataTable行迭代并替换
string schoolName = Convert。 Tostring(objDs.Tables [0] .Rows [intCount] [1]);
objDs.Tables [0] .Rows [intCount] [1] = Regex.Replace(schoolName,@[\d - ],string.Empty);
然后,
objDs.Tables [0] .AcceptChanges();
希望这有帮助
string strConn = ConfigurationManager.ConnectionStrings["conStr"].ConnectionString;
SqlConnection con = new SqlConnection(strConn);
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "Select intschoolcode,varschoolname from tblSchool_Master where varclustercode = '" + areaid.ToString() +"'";
DataSet objDs = new DataSet();
SqlDataAdapter dAdapter = new SqlDataAdapter();
dAdapter.SelectCommand = cmd;
con.Open();
dAdapter.Fill(objDs);
con.Close();
if (objDs.Tables[0].Rows.Count > 0)
{
ddlschool.DataSource = objDs.Tables[0];
ddlschool.DataTextField = "varschoolname";
ddlschool.DataValueField = "intschoolcode";
ddlschool.DataBind();
ddlschool.Items.Insert(0, "--Select--");
}
else
{
}
Here I want to remove numbers from varschoolname data which is in the database.How should I do it?
解决方案
You can try Regex for the same.
Iterate through the DataTable Rows and replace
string schoolName = Convert.Tostring( objDs.Tables[0].Rows[intCount][1]); objDs.Tables[0].Rows[intCount][1] = Regex.Replace(schoolName,@"[\d-]",string.Empty);
And then ,
objDs.Tables[0].AcceptChanges();
Hope this helps
这篇关于从数据集中删除数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文