Try This
private void button1_Click(object sender, EventArgs e)
{
BindProducts();
BindGridView();
}
private void BindProducts()
{
string a = "233Adsf 48872Hjyu 1289Rtop";
string[] words = a.Split(' ');
foreach (string word in words)
{
string myString = word;
string alphabet = String.Empty;
string digit = String.Empty;
Match regexMatch = Regex.Match(myString, @"\D+");
if (regexMatch.Success) //Found numeric part in the coverage string
{
int digitStartIndex = regexMatch.Index; //Get the index where the numeric digit found
digit = myString.Substring(0, digitStartIndex);
alphabet = myString.Substring(digitStartIndex);
string sqlConnectionString = ConfigurationManager.ConnectionStrings["connection"].ConnectionString.ToString();
SqlConnection con = new SqlConnection(sqlConnectionString);
con.Open();
SqlCommand cmd = new SqlCommand("insert into Test2 values('" + digit + "','" + alphabet + "')", con);
cmd.ExecuteNonQuery();
con.Close();
}
}
}
private void BindGridView()
{
string constring = ConfigurationManager.ConnectionStrings["connection"].ConnectionString.ToString();
using (SqlConnection con = new SqlConnection(constring))
{
using (SqlCommand cmd = new SqlCommand("SELECT * FROM Test2", con))
{
cmd.CommandType = CommandType.Text;
using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
{
using (DataTable dt = new DataTable())
{
sda.Fill(dt);
dataGridView1.DataSource = dt;
}
}
}
}
}