Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
C#
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?
Posted
Updated 1-Nov-13 3:24am
v3
Comments
thatraja 1-Nov-13 3:51am    
show sample data & output
OriginalGriff 1-Nov-13 4:00am    
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind.
Perhaps an example would help?
Use the "Improve question" widget to edit your question and provide better information.
[no name] 1-Nov-13 5:23am    
When you provide all details, also add that the solution require is the query to be executed to change the data permananet in Database or you need to modify the contents during application execution and display to user.
Rahul_Pandit 1-Nov-13 9:38am    
Your question is not clear wheather your dropdown list contains numbers in list or numbers are concated with list items like---

1
hello
2
yes
no

or----------

a1113
b5
c9
Muhammad Naveed 3-Nov-13 1:32am    
Which number you want to remove? Put your sample data which you want to show and which you want to be removed..

1 solution

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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900