c# - How do I store source code lines in SQL Server Database and access it via DataSet -


i want store following code 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 in dataset , display on page.

as of have stored questions varchar(max) datatype when try in dataset following error:

failed enable constraints. 1 or more rows contain values violating non-null, unique, or foreign-key constraints.

i doing in asp.net web application.

edit: here table definition of table inserting data

database definition

the query using insert data table:

con.connectionstring = constr;     cmd.connection = con;     cmd.commandtext = "insert 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 = cmd.executenonquery();     con.close(); 

and code extracting data dataset

dataset1.questabledatatable dt = new dataset1.questabledatatable();     dataset1tableadapters.questabletableadapter adp = new dataset1tableadapters.questabletableadapter();     dt = adp.getdata();     datatable dtuser = dt.clone(); 

hope information helpful.

since can't see if you've got other further constraints on table, looks value you're inserting primary key field (qid) exists in table.

if need create new row every entry regardless, easier change column qid maintain own identity. if need update existing value, you'll need add separate piece of logic determine if primary key value exists , update or insert accordingly.


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -