.NET Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgramming.NET Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old October 21st, 2009, 06:48 AM
JeromeJr JeromeJr is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2009
Posts: 18 JeromeJr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 56 m
Reputation Power: 0
Question VBScript - Database - General - Update wont work

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

Reply With Quote
  #2  
Old October 21st, 2009, 07:15 AM
micky's Avatar
micky micky is offline
Couch Potato Wizard
Click here for more information. Click here for more information
 
Join Date: Jan 2005
Location: India
Posts: 12,259 micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)  Folding Points: 1480 Folding Title: Novice Folder
Time spent in forums: 5 Months 4 Days 2 m 48 sec
Reputation Power: 2179
Hi and welcome to the forums
Have you debugged and seen if it goes in IF loop??
Code:
if (NgramID != null)
__________________
Laziness is my religion and Sunday is my God

Get the Mantra!

Reply With Quote
  #3  
Old October 21st, 2009, 07:16 AM
JeromeJr JeromeJr is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2009
Posts: 18 JeromeJr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 56 m
Reputation Power: 0
ill try when i come home, im at work now, thx

Reply With Quote
  #4  
Old October 21st, 2009, 07:20 AM
JeromeJr JeromeJr is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2009
Posts: 18 JeromeJr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 56 m
Reputation Power: 0
and now stupid question
what if it goes?
what to do ?

Reply With Quote
  #5  
Old October 21st, 2009, 07:26 AM
micky's Avatar
micky micky is offline
Couch Potato Wizard
Click here for more information. Click here for more information
 
Join Date: Jan 2005
Location: India
Posts: 12,259 micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)  Folding Points: 1480 Folding Title: Novice Folder
Time spent in forums: 5 Months 4 Days 2 m 48 sec
Reputation Power: 2179
Quote:
Originally Posted by JeromeJr
and now stupid question
what if it goes?
what to do ?
actually its not a stupid question

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);

Reply With Quote
  #6  
Old October 21st, 2009, 07:28 AM
JeromeJr JeromeJr is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2009
Posts: 18 JeromeJr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 56 m
Reputation Power: 0
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

Reply With Quote
  #7  
Old October 21st, 2009, 07:34 AM
micky's Avatar
micky micky is offline
Couch Potato Wizard
Click here for more information. Click here for more information
 
Join Date: Jan 2005
Location: India
Posts: 12,259 micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)  Folding Points: 1480 Folding Title: Novice Folder
Time spent in forums: 5 Months 4 Days 2 m 48 sec
Reputation Power: 2179
Quote:
Originally Posted by JeromeJr
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
no problem

Reply With Quote
  #8  
Old October 21st, 2009, 12:54 PM
JeromeJr JeromeJr is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2009
Posts: 18 JeromeJr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 56 m
Reputation Power: 0
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

Reply With Quote
  #9  
Old October 22nd, 2009, 04:08 AM
micky's Avatar
micky micky is offline
Couch Potato Wizard
Click here for more information. Click here for more information
 
Join Date: Jan 2005
Location: India
Posts: 12,259 micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)micky User rank is General 18th Grade (Above 100000 Reputation Level)  Folding Points: 1480 Folding Title: Novice Folder
Time spent in forums: 5 Months 4 Days 2 m 48 sec
Reputation Power: 2179
Quote:
Originally Posted by JeromeJr
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
Did it go in that IF loop where you are updating records??

Reply With Quote
  #10  
Old October 22nd, 2009, 04:17 AM
JeromeJr JeromeJr is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2009
Posts: 18 JeromeJr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 56 m
Reputation Power: 0
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 ?

Reply With Quote
  #11  
Old October 22nd, 2009, 03:12 PM
JeromeJr JeromeJr is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2009
Posts: 18 JeromeJr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 56 m
Reputation Power: 0
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

Reply With Quote
  #12  
Old October 22nd, 2009, 04:07 PM
Rictor's Avatar
Rictor Rictor is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Mar 2006
Posts: 326 Rictor User rank is Captain (20000 - 30000 Reputation Level)Rictor User rank is Captain (20000 - 30000 Reputation Level)Rictor User rank is Captain (20000 - 30000 Reputation Level)Rictor User rank is Captain (20000 - 30000 Reputation Level)Rictor User rank is Captain (20000 - 30000 Reputation Level)Rictor User rank is Captain (20000 - 30000 Reputation Level)Rictor User rank is Captain (20000 - 30000 Reputation Level)Rictor User rank is Captain (20000 - 30000 Reputation Level)Rictor User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Week 1 Day 18 h 3 m 9 sec
Reputation Power: 213
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.

Reply With Quote
  #13  
Old October 22nd, 2009, 04:14 PM
JeromeJr JeromeJr is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2009
Posts: 18 JeromeJr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 56 m
Reputation Power: 0
Question

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

Reply With Quote
  #14  
Old October 22nd, 2009, 05:19 PM
Rictor's Avatar
Rictor Rictor is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Mar 2006
Posts: 326 Rictor User rank is Captain (20000 - 30000 Reputation Level)Rictor User rank is Captain (20000 - 30000 Reputation Level)Rictor User rank is Captain (20000 - 30000 Reputation Level)Rictor User rank is Captain (20000 - 30000 Reputation Level)Rictor User rank is Captain (20000 - 30000 Reputation Level)Rictor User rank is Captain (20000 - 30000 Reputation Level)Rictor User rank is Captain (20000 - 30000 Reputation Level)Rictor User rank is Captain (20000 - 30000 Reputation Level)Rictor User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Week 1 Day 18 h 3 m 9 sec
Reputation Power: 213
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.

Reply With Quote
  #15  
Old October 26th, 2009, 05:38 AM
JeromeJr JeromeJr is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Oct 2009
Posts: 18 JeromeJr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 56 m
Reputation Power: 0
didn't help

and what about using dictionary class to store ID's after "select" query and then try to update?

Reply With Quote
Reply

Viewing: ASP Free ForumsProgramming.NET Development > VBScript - Database - General - Update wont work


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump





 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek