So here's my code...
string connectionString = null;
string sql = null;
connectionString = "Server=(localdb)\\v11.0;Integrated Security=true;";
using (SqlConnection cnn = new SqlConnection(connectionString))
{
sql = "INSERT INTO EmailParser (Sender,Building,Level,Phase,Request) values(@Sender,@Building,@Level,@Phase,@Request)";
cnn.Open();
using (SqlCommand cmd = new SqlCommand(sql, cnn))
{
String d1 = m.Groups[4].ToString();
String d2 = m.Groups[9].ToString();
String int1 = m.Groups[14].ToString();
String word1 = m.Groups[19].ToString();
cmd.Parameters.AddWithValue("@Sender", email.From);
cmd.Parameters.AddWithValue("@Building", d1);
cmd.Parameters.AddWithValue("@Level", d2);
cmd.Parameters.AddWithValue("@Phase", int1);
cmd.Parameters.AddWithValue("@Request", word1);
cmd.ExecuteNonQuery();}
The d1, d2, int1, and word1 are from the RegEx...
string re4 = "(\\d)";
string re9 = "(\\d)";
string re14 = "(\\d+)";
string re19 = "([A-Za-z0-9/-]+)";
What I have tried:
I think the error is from the parameters but I can't still figure out what's wrong with my code. d1, d2, int1, and word1 are all in string so why can't those be inserted on my database? The data types of the fields are all nvarchar. I assume nvarchar are strings right?