1

I want to store the following code into the database:

fun(...);

int main()
{
    fun(3, 7, -11.2, 0.66);
    return 0;
}
fun(...)
{
    va_list ptr;
    int num;
    va_start(ptr, n);
    num = va_arg(ptr, int);
    printf("%d", num);
}

and then get it back in the dataset and display on a page.

As of now I have successfully stored the questions with varchar(MAX) datatype but when I try to get it in the dataset i get the following error:

Failed To Enable Constraints. One Or More Rows Contain Values Violating Non-null, Unique, Or Foreign-key Constraints.

I am doing this in a ASP.NET web application.

EDIT: Here is the Table definition of the table I am inserting the data into

Database Definition

The query I am using to insert the data into the table:

con.ConnectionString = constr;
    cmd.Connection = con;
    cmd.CommandText = "insert into QuesTable values(@D1,@D2,@D3,@D4,@D5,@D6,@D7, NULL)";
    cmd.Parameters.Add("@D1", SqlDbType.Int).Value = txtQID.Text;
    cmd.Parameters.Add("@D2", SqlDbType.VarChar).Value = txtques.Text;
    cmd.Parameters.Add("@D3", SqlDbType.VarChar).Value = txtansa.Text;
    cmd.Parameters.Add("@D4", SqlDbType.VarChar).Value = txtansb.Text;
    cmd.Parameters.Add("@D5", SqlDbType.VarChar).Value = txtansc.Text;
    cmd.Parameters.Add("@D6", SqlDbType.VarChar).Value = txtansd.Text;
    cmd.Parameters.Add("@D7", SqlDbType.VarChar).Value = txtcorr.Text;

    con.Open();
    int i = cmd.ExecuteNonQuery();
    con.Close();

And finally the code by which I am extracting the data from the dataset

DataSet1.QuesTableDataTable dt = new DataSet1.QuesTableDataTable();
    DataSet1TableAdapters.QuesTableTableAdapter adp = new DataSet1TableAdapters.QuesTableTableAdapter();
    dt = adp.GetData();
    DataTable dtUser = dt.Clone();

Hope the information is helpful.

5
  • Can you post the SQL statement your using to insert and the definition of the table you're inserting into? Commented Mar 1, 2011 at 14:10
  • What's Ansa Ansb and ansc? Why not have an answers table so you don't need to split this stuff out? Commented Mar 1, 2011 at 17:12
  • Ansa is Option A, Option B, and so on ... Commented Mar 1, 2011 at 17:23
  • So what happens if the requirements change and there's now an option e? Commented Mar 1, 2011 at 17:32
  • its a small project n no scope for option e in the initial release.. will scale up in the future Commented Mar 1, 2011 at 17:38

2 Answers 2

1

Since I can't see if you've got any other further constraints on the table, it looks like the value you're inserting into the primary key field (Qid) already exists in the table.

If you need to create a new row for every entry regardless, it would probably be easier to change the column Qid to maintain its own Identity. If you need to update an existing value, you'll need to add a separate piece of logic to determine if the primary key value already exists and update or insert accordingly.

Sign up to request clarification or add additional context in comments.

Comments

0

That's an error related to either:

  • A not null field is having a null passed in when you load the data.
  • A foreign key or unique index check is invalid (for instance, FK value of 9 doesn't exist).

If you fill the dataset, the error that is generated should be retrievable from the dataset.

HTH.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.