c# - Two foreign keys in one table using SQL Server in asp.net webform -
i've created bidtable
in i've used 2 foreign keys i.e id reg
table & carid
submitadd
table.
id reg
table fetched comparison of username current session's username while carid
fetched comparing query string id
carid
.
the problem when use both of them in bidtable
foreign keys, bidtable
can not fetch both of data. when use them separately, example use id
reg
in bidtable
foreign key, works perfectly.
here's code:
string cs = configurationmanager.connectionstrings["conn"].connectionstring; using (sqlconnection con = new sqlconnection(cs)) { sqlcommand cmdd2 = new sqlcommand("select * submitadd carid='"+ request.querystring["id"].tostring() + "'", con);//taking carid querystring con.open(); sqldataadapter sdda = new sqldataadapter(cmdd2); datatable dtt = new datatable(); sdda.fill(dtt); sqlcommand cmdd = new sqlcommand("select * reg username='"+ session["username"] + "'", con); sqldataadapter sda = new sqldataadapter(cmdd); datatable dt = new datatable(); sda.fill(dt); if (dtt.rows.count != 0 && dt.rows.count != 0) { int id = convert.toint32(dt.rows[0][0]); // registration id reg table int carid = convert.toint32(dtt.rows[0][0]);// carid submitadd table string ss = "insert bidtable values('" + id + "','" + carid + "','" + textbid.text + "')"; sqlcommand cmd = new sqlcommand(ss, con); sqldataadapter sda2 = new sqldataadapter(cmd); datatable dt2 = new datatable(); sda2.fill(dt2); } }
please check join while fetching records, if dont have either category id or userid , if using inner join records ommited. use left join.
Comments
Post a Comment