Hi Arvind,
I dont know what you are trying to ask here you want to insert data using SP, but you have tagged with Asp.Net.
I took ASP.Net as first priority and tried this
First split the string and then pass it to either insert query or to sp as you wish.
protected void Page_Load(object sender, EventArgs e)
{
string temp1 = @"('Aloo','fry','54',1,5)('DalTadka','fyr','34',1,5)";
bool val = splitRow(temp1);
}
private bool splitRow(string fullRow)
{
string inputRowVal=string.Empty;
foreach (var row in fullRow.Split(')'))
{
inputRowVal = row.Replace("(", "");
SplitAndInsert(Convert.ToString(inputRowVal));
}
return true;
}
private bool SplitAndInsert(string inputString)
{
bool isInserted = false;
string temp=string.Empty;
int count = 0;
string[] param=new string[5];
foreach (var str in inputString.Split(','))
{
if (str.Contains("'"))
{
param[count] = str.Replace("'", "");
}
else
{
param[count] = str;
}
count++;
}
if (param != null && param.Count() == 5)
{
using(SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["connSpionshopString"].ConnectionString))
{
connection.Open();
string sql = "INSERT INTO yourTableName VALUES(@param1,@param2,@param3,@param4,@param5)";
SqlCommand cmd = new SqlCommand(sql,connection);
cmd.Parameters.Add("@param1", SqlDbType.VarChar).Value = param[0];
cmd.Parameters.Add("@param2", SqlDbType.VarChar).Value = param[1];
cmd.Parameters.Add("@param3", SqlDbType.Int).Value = Convert.ToInt32(param[2]);
cmd.Parameters.Add("@param4", SqlDbType.Int).Value = Convert.ToInt32(param[3]);
cmd.Parameters.Add("@param5", SqlDbType.Int).Value = Convert.ToInt32(param[4]);
cmd.CommandType = CommandType.Text;
if (cmd.ExecuteNonQuery()==1)
{
isInserted = true;
}
}
}
return isInserted;
}
If you pass SplitAndInsert(@"'Aloo','fry','54',1,5") like this then it will split and inserted in the database.
Just take it as reference.
Hope this helps you.
Regards,
RK