Jump to content

chk if founded in db


Matar
 Share

Recommended Posts

hi allthis is a code to serach if this item in my db ,, if exsist this is error ,elseadd it to my db but it doesn't work

<%dim wh_card1wh_card1 = request.form("wh_card")dim conn1dim rs1dim sql1Set Conn1 = Server.CreateObject("ADODB.Connection")conn1.Provider="Microsoft.Jet.OLEDB.4.0"conn1.Open(Server.Mappath("/webdata/atc.mdb"))set rs1 = Server.CreateObject("ADODB.recordset")      RS1.open "reg",Connsql1 = "select * form reg where wh_card = '"& Request.Form("wh_card") & "'"set RS1 = Conn.Execute(sql1)if  not rs1.eof then response.Redirect ("error.asp?error=duplicate")%><%dim namedim avgdim secdim yerdim soudim schdim gendim mat_studim reldim pobdim dopdim moth_namedim natdim org_coudim addressdim teldim post_adddim podim dad_namedim dad_jobdim dad_reladim work_undim unjob_nodim flag_servdim flagserv_nodim wh_carddim wh_sodim shgdim shg_nodim any_undim any_namedim any_cendim op1dim op2dim op3dim op4name = request.form("name")avg = request.form("avg_sec")sec = request.form("sec_sec")yer = request.form("sec_year")sou = request.form("sec_sou")sch = request.form("last_sch")gen = request.form("gen")mat_stu= request.form("mat_stu")rel = request.form("rel")pob = request.form("pob")dop = request.form("dop")moth_name = request.form("moth_name")nat = request.form("nat")org_cou = request.form("org_cou")address = request.form("address")tel = request.form("tel")post_add = request.form("post_add")po = request.form("po")dad_name = request.form("dad_name")dad_job = request.form("dad_job")dad_rela = request.form("dad_rela")work_un = request.form("work_un")unjob_no = request.form("unjob_no")flag_serv = request.form("flag_serv")flagserv_no = request.form("flagserv_no")wh_card = request.form("wh_card")wh_so = request.form("wh_so")shg = request.form("shg")shg_no = request.form("shg_no")anyun = request.form("any_un")any_name = request.form("any_name")any_cen = request.form("any_cen")op1 = request.form("op1")op2 = request.form("op2")op3 = request.form("op3")op4 = request.form("op4")Dim conn            Dim rs  Set Conn = Server.CreateObject("ADODB.Connection")conn.Provider="Microsoft.Jet.OLEDB.4.0"conn.Open(Server.Mappath("/webdata/atc.mdb"))set rs = Server.CreateObject("ADODB.recordset")      RS.open "reg",Conn,2,2rs.AddNewrs.Fields("Name") = Request.Form("name")rs.Fields("avg_sec") = Request.Form("avg_sec")rs.Fields("sec_sec") = Request.Form("sec_sec")rs.Fields("sec_year") = Request.Form("sec_year")rs.Fields("sec_sou") = Request.Form("sec_sou")rs.Fields("last_sch") = Request.Form("last_sch")rs.Fields("gen") = Request.Form("gen")rs.Fields("mat_stu") = Request.Form("mat_stu")rs.Fields("rel") = Request.Form("rel")rs.Fields("pob") = Request.Form("pob")rs.Fields("dob") = Request.Form("dop")rs.Fields("moth_name") = Request.Form("moth_name")rs.Fields("nat") = Request.Form("nat")rs.Fields("org_cou") = Request.Form("org_cou")rs.Fields("address") = Request.Form("address")rs.Fields("tel") = Request.Form("tel")rs.Fields("post_add") = Request.Form("post_add")rs.Fields("po") = Request.Form("po")rs.Fields("dad_name") = Request.Form("dad_name")rs.Fields("dad_job") = Request.Form("dad_job")rs.Fields("dad_rela") = Request.Form("dad_rela")rs.Fields("work_un") = Request.Form("work_un")rs.Fields("unjob_no") = Request.Form("unjob_no")rs.Fields("flag_serv") = Request.Form("flag_serv")rs.Fields("flagserv_no") = Request.Form("flagserv_no")rs.Fields("wh_card") = Request.Form("wh_card")rs.Fields("wh_so") = Request.Form("wh_so")rs.Fields("shg") = Request.Form("shg")rs.Fields("shg_no") = Request.Form("shg_no")rs.Fields("any_un") = Request.Form("any_un")rs.Fields("any_name") = Request.Form("any_name")rs.Fields("any_cen") = Request.Form("any_cen")rs.Fields("op1") = Request.Form("op1")rs.Fields("op2") = Request.Form("op2")rs.Fields("op3") = Request.Form("op3")rs.Fields("op4") = Request.Form("op4")rs.Updaters.CloseSet rs = NothingSet Conn = NothingResponse.Redirect "thx.asp"%>
and i see this errorError Type:ADODB.Recordset (0x800A0BB9)Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another./add.asp, line 11what i should do ?
Link to comment
Share on other sites

No offense, but you have really bad English.With reference to your error, the first thing to do is read the error and see what it says. It says there is a bad argument on line 11. This is line 11:set RS1 = Conn.Execute(sql1)The SQL statement being executed is right above, on line 10:sql1 = "select * form reg where wh_card = '"& Request.Form("wh_card") & "'"set RS1 = Conn.Execute(sql1)You probably want to make sure your SQL statement is using the correct syntax.sql1 = "select * form reg where wh_card = '"& Request.Form("wh_card") & "'"

Link to comment
Share on other sites

Matar,You've got a lot of errors in your code.

<%dim wh_card1wh_card1 = request.form("wh_card")dim rs1dim sql1Set Conn1 = Server.CreateObject("ADODB.Connection")conn1.Provider="Microsoft.Jet.OLEDB.4.0"conn1.Open(Server.Mappath("/webdata/atc.mdb"))set rs1 = Server.CreateObject("ADODB.recordset")RS1.open "reg",Connsql1 = "select * form reg where wh_card = '" & Request.Form("wh_card") & "'"set RS1 = Conn.Execute(sql1)if  not rs1.eof then response.Redirect ("error.asp?error=duplicate")end if
The code in red is wrong. First, the syntax for opening a table looks like this:RecordSet.Open sql_query, connection[, cursortype, locktype]. (Cursortype and locktype are optional.) That means, the statement RS1.Open "reg" opens your your reg table, by executeing the SQL query "reg", which returns all the rows and all the columns from your reg table. You probably don't want to do that, it eats up all of your server resources and it causes the page to load very very slowly.You wouldn't be able to open up your table in the first place, because you've declared a variable called Conn1, but you're trying to open your recordset on a variable called Conn. You're going to get a "connection not open" error. I'm not sure why you are trying to open two recordsets and two connections at the same time, you only need one.Also, after you open up all of the contents from your reg table in the first line, you perform another SQL query directly afterward. So you are performing two queries, when you only need one. More importantly, you've already opened a recordset with RS.Open, and now you are trying to perform another query with Conn.Execute without closing your other recordset, so you are going to get a "cannot execute query on open recordset" error. Also note that you aren't using correct SQL syntax in your SQL statement; you use "SELECT * form" when you should be using "SELECT * from".Then, if your new query returns a match, you forward the user to another page without closing your recordset or connection (thats bad).You should rewrite the code in red to this:
Dim Conn1, RS1, sql1Set Conn1 = Server.CreateObject("ADODB.Connection")conn1.Provider="Microsoft.Jet.OLEDB.4.0"conn1.Open(Server.Mappath("/webdata/atc.mdb"))set rs1 = Server.CreateObject("ADODB.recordset")sql1 = "select * from reg where wh_card = '"& Request.Form("wh_card") & "'"RS1.open sql1,Conn1, 3, 3     'its better to explicitly state your cursortype and locktypesif  not rs1.eof then    'closing recordset and connection before forwarding to another page.    rs1.close    conn.close    set rs1 = nothing    set conn = nothing    response.Redirect ("error.asp?error=duplicate")end if

dim namedim avgdim secdim yerdim soudim schdim gendim mat_studim reldim pobdim dopdim moth_namedim natdim org_coudim addressdim teldim post_adddim podim dad_namedim dad_jobdim dad_reladim work_undim unjob_nodim flag_servdim flagserv_nodim wh_carddim wh_sodim shgdim shg_nodim any_undim any_namedim any_cendim op1dim op2dim op3dim op4name = request.form("name")avg = request.form("avg_sec")sec = request.form("sec_sec")yer = request.form("sec_year")sou = request.form("sec_sou")sch = request.form("last_sch")gen = request.form("gen")mat_stu= request.form("mat_stu")rel = request.form("rel")pob = request.form("pob")dop = request.form("dop")moth_name = request.form("moth_name")nat = request.form("nat")org_cou = request.form("org_cou")address = request.form("address")tel = request.form("tel")post_add = request.form("post_add")po = request.form("po")dad_name = request.form("dad_name")dad_job = request.form("dad_job")dad_rela = request.form("dad_rela")work_un = request.form("work_un")unjob_no = request.form("unjob_no")flag_serv = request.form("flag_serv")flagserv_no = request.form("flagserv_no")wh_card = request.form("wh_card")wh_so = request.form("wh_so")shg = request.form("shg")shg_no = request.form("shg_no")anyun = request.form("any_un")any_name = request.form("any_name")any_cen = request.form("any_cen")op1 = request.form("op1")op2 = request.form("op2")op3 = request.form("op3")op4 = request.form("op4")Dim conn            Dim rs  Set Conn = Server.CreateObject("ADODB.Connection")conn.Provider="Microsoft.Jet.OLEDB.4.0"conn.Open(Server.Mappath("/webdata/atc.mdb"))set rs = Server.CreateObject("ADODB.recordset")      RS.open "reg",Conn,2,2
By this point in your code, you've already got a recordset and a connection already open. You don't need to open another recordset, and if you try to open another connection on your Conn variable without closing it, then you're going to get a "connection already open" error.You don't need any of the code in red, you should delete it. However, since you're going to be deleting it, you need to change call of your RS fieldnames below to RS1, so that they match your existing recordset variable.
rs1.AddNewrs1.Fields("Name") = Request.Form("name")rs1.Fields("avg_sec") = Request.Form("avg_sec")rs1.Fields("sec_sec") = Request.Form("sec_sec")rs1.Fields("sec_year") = Request.Form("sec_year")rs1.Fields("sec_sou") = Request.Form("sec_sou")rs1.Fields("last_sch") = Request.Form("last_sch")rs1.Fields("gen") = Request.Form("gen")rs1.Fields("mat_stu") = Request.Form("mat_stu")rs1.Fields("rel") = Request.Form("rel")rs1.Fields("pob") = Request.Form("pob")rs1.Fields("dob") = Request.Form("dop")rs1.Fields("moth_name") = Request.Form("moth_name")rs1.Fields("nat") = Request.Form("nat")rs1.Fields("org_cou") = Request.Form("org_cou")rs1.Fields("address") = Request.Form("address")rs1.Fields("tel") = Request.Form("tel")rs1.Fields("post_add") = Request.Form("post_add")rs1.Fields("po") = Request.Form("po")rs1.Fields("dad_name") = Request.Form("dad_name")rs1.Fields("dad_job") = Request.Form("dad_job")rs1.Fields("dad_rela") = Request.Form("dad_rela")rs1.Fields("work_un") = Request.Form("work_un")rs1.Fields("unjob_no") = Request.Form("unjob_no")rs1.Fields("flag_serv") = Request.Form("flag_serv")rs1.Fields("flagserv_no") = Request.Form("flagserv_no")rs1.Fields("wh_card") = Request.Form("wh_card")rs1.Fields("wh_so") = Request.Form("wh_so")rs1.Fields("shg") = Request.Form("shg")rs1.Fields("shg_no") = Request.Form("shg_no")rs1.Fields("any_un") = Request.Form("any_un")rs1.Fields("any_name") = Request.Form("any_name")rs1.Fields("any_cen") = Request.Form("any_cen")rs1.Fields("op1") = Request.Form("op1")rs1.Fields("op2") = Request.Form("op2")rs1.Fields("op3") = Request.Form("op3")rs1.Fields("op4") = Request.Form("op4")rs1.Updaters1.CloseSet rs1 = NothingSet Conn1 = NothingResponse.Redirect "thx.asp"%>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...