|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
hello, im new here, have one big problem,
Code:
// save bigram
foreach(Ngram ngram in m_bigramCharList)
{
cmd = new OleDbCommand("select ID from BigramChar where bigram = @bigram", conn);
cmd.Parameters.Add(new OleDbParameter("@bigram", ngram.Znakovi));
object NgramID = cmd.ExecuteScalar(); cmd.Dispose();
// if there is bigram then update else insert into table
if (NgramID != null)
{
int iNgramID = (int)NgramID;
cmd = new OleDbCommand("UPDATE BigramChar SET bigram_broj = bigram_broj + @bigram_broj, bigram_txt = bigram_txt + @bigram_txt where ID = @ID", conn);
cmd.Parameters.Add(new OleDbParameter("@ID", iNgramID));
cmd.Parameters.Add(new OleDbParameter("@bigram_broj", ngram.Count));
cmd.Parameters.Add(new OleDbParameter("@bigram_txt", BrojZnakova));
cmd.ExecuteNonQuery();
cmd.Dispose();
}
else
{
cmd = new OleDbCommand("insert into BigramChar (JezikID, bigram, bigram_broj, bigram_txt) values (@JezikID, @bigram, @bigram_broj, @bigram_txt)", conn);
cmd.Parameters.Add(new OleDbParameter("@JezikID", JezikID));
cmd.Parameters.Add(new OleDbParameter("@bigram", ngram.Znakovi));
cmd.Parameters.Add(new OleDbParameter("@bigram_broj", ngram.Count));
cmd.Parameters.Add(new OleDbParameter("@bigram_txt", BrojZnakova));
cmd.ExecuteNonQuery();
cmd.Dispose();
}
}
so, problem is that code for update wont work, it seems to be good and i really dont know how else to write it, can someone please help thanks |
|
#2
|
||||
|
||||
|
Hi and welcome to the forums
Have you debugged and seen if it goes in IF loop?? Code:
if (NgramID != null) |
|
#3
|
|||
|
|||
|
ill try when i come home, im at work now, thx
![]() |
|
#4
|
|||
|
|||
|
and now stupid question
![]() what if it goes? what to do ? |
|
#5
|
||||
|
||||
|
Quote:
![]() Well to me, query looks good, so it should run or throw any error. I am not fluent in C#, but may be you can try adding some brackets in query like this........ its just a shot in the dark ![]() Code:
cmd = new OleDbCommand("UPDATE BigramChar SET (bigram_broj = bigram_broj + @bigram_broj), (bigram_txt = bigram_txt + @bigram_txt) where ID = @ID", conn);
|
|
#6
|
|||
|
|||
|
well im new too, as i can see querry is good and loop is good, ill se what debugger say and reply in few hours
|
|
#7
|
||||
|
||||
|
Quote:
![]() |
|
#8
|
|||
|
|||
|
code is clean as debugger didn't show any error, and query too, i really don't know what to do next, brackets don't help
![]() |
|
#9
|
||||
|
||||
|
Quote:
|
|
#10
|
|||
|
|||
|
ill just try to insert @ID value into blank table to see what is he inserting
only problem and main can be when he found multiple id's id is number of autonumber field of founded bigram (as example bigram = 'as') and when he found multiple bigrams to update that's maybe the problem, i have to save it into other table and then just with querry update those fields ? |
|
#11
|
|||
|
|||
|
with text
"hi im new" in textbox im getting values into my table ID JezikID bigram bigram_broj bigram_txt 141 3 hi 1 7 142 3 i 1 7 143 3 im 1 7 144 3 m 1 7 145 3 n 1 7 146 3 ne 1 7 147 3 ew 1 7 on statement Code:
foreach(Ngram ngram in m_bigramCharList)
{
cmd = new OleDbCommand("select ID from BigramChar where bigram = @bigram", conn);
cmd.Parameters.Add(new OleDbParameter("@bigram", ngram.Znakovi));
object NgramID = cmd.ExecuteScalar();
cmd.Dispose();
// ako ne postoji ngram, insert, ako postoji, update...
if (NgramID != null)
{
int iNgramID = (int)NgramID;
cmd = new OleDbCommand("insert into tbl_ID (charID) VALUES (@ID)", conn);
cmd.Parameters.Add(new OleDbParameter("@ID", NgramID));
im getting values ID charID 159 141 160 132 161 142 162 143 163 144 164 145 165 146 166 147 so he founded id's in table but he wont to update ![]() |
|
#12
|
||||
|
||||
|
I think when you use just add - it's a lot more picky unless you actually specify which datatype it is set to in the database, in the command itself. I've found addwithvalue a lot easier.
Try changing it addwithvalue.... Code:
cmd.Parameters.AddWithValue(new OleDbParameter("@ID", iNgramID));
cmd.Parameters.AddWithValue(new OleDbParameter("@bigram_broj", ngram.Count));
cmd.Parameters.AddWithValue(new OleDbParameter("@bigram_txt", BrojZnakova));
Last edited by Rictor : October 22nd, 2009 at 04:09 PM. |
|
#13
|
|||
|
|||
|
Code:
cmd = new OleDbCommand("UPDATE BigramChar SET bigram_broj = bigram_broj + @bigram_broj, bigram_txt = bigram_txt + @bigram_txt where ID = @ID", conn);
cmd.Parameters.AddWithValue(new OleDbParameter("@ID", NgramID));
cmd.Parameters.AddWithValue(new OleDbParameter("@JezikID", JezikID));
cmd.Parameters.AddWithValue(new OleDbParameter("@bigram_broj", ngram.Count));
cmd.Parameters.AddWithValue(new OleDbParameter("@bigram_txt", BrojZnakova));
cmd.ExecuteNonQuery();
cmd.Dispose();
im getting this error from compiler Compiler Error Message: CS1501: No overload for method 'AddWithValue' takes '1' arguments Error 1 No overload for method 'AddWithValue' takes '1' arguments and i cant compile project |
|
#14
|
||||
|
||||
|
Try this:
Code:
cmd.Parameters.AddWithValue("ID", NgramID);
cmd.Parameters.AddWithValue("JezikID", JezikID);
cmd.Parameters.AddWithValue("bigram_broj", ngram.Count);
cmd.Parameters.AddWithValue("bigram_txt", BrojZnakova);
cmd.ExecuteNonQuery();
Last edited by Rictor : October 22nd, 2009 at 05:27 PM. |
|
#15
|
|||
|
|||
|
didn't help
and what about using dictionary class to store ID's after "select" query and then try to update? |
![]() |
| Viewing: ASP Free Forums > Programming > .NET Development > VBScript - Database - General - Update wont work |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|