hi i've parse the string in c sharp and got the array of string and i want to save this array of string in sql databse in different column like id in id column, description in description column. Now my problem is whenever i execcute my insert query the data is inserted in the db but it is null.

Any help will be appreciated.

Thanx

Just a rough approximation here and you'll need to set up your own connection strings and variables and inputs and such but here's how I'd go about achieving what you're asking for:

protected bool testIt()
    {
        string[] parsedData = test.Text.Split(',');
        blConn connector = new blConn();
        string connStr = @connector.cString;
        SqlConnection insertConn = new SqlConnection(@connStr);
        SqlCommand insertCmd = insertConn.CreateCommand();
        insertCmd.CommandText = @"INSERT INTO dbNameHere (id,description,etc) VALUES (@id,@desc,@etc)";
        insertCmd.Parameters.Add("@id", SqlDbType.Int);
        insertCmd.Parameters["@id"].Value = Convert.ToInt16(parsedData[0]);
        insertCmd.Parameters.Add("@desc", SqlDbType.VarChar);
        insertCmd.Parameters["@desc"].Value = parsedData[1];
        insertCmd.Parameters.Add("@etc", SqlDbType.VarChar);
        insertCmd.Parameters["@etc"].Value = parsedData[2];
        insertConn.Open();
        int confirm = insertCmd.ExecuteNonQuery();
        insertConn.Close();
        if (confirm == 0)
        {
            return false;
        }
        else
        {
            return true;
        }
    }

In my example above blConn is actually an invoked class containing my connection string to my DB.
Hope it helps :) Mark as solved if it resolves your issue.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.