Okay Basically i want to put the contents of array called numbers
into a MSSQL database

i can connect to it no problem and select and display data
so its not a connectivity issue

here is what i have so far:

for (int i = 0; i < numbers.length; i++)
{
   String sql "INSERT INTO smsmsg(to, msg,from, timesent)VALUES ('number[i]', 'text', 'from', GETDATE())";
   access.insert(sqli);

}

Please note Numbers is the array

any help would be appreciated i am new to this and going nuts

> can connect to it no problem and select and display data
so its not a connectivity issue...

How did you manage that one?

>Why you wrote this? - Incorrect code. I can't find more words about this code.

for (int i = 0; i < numbers.length; i++) {
   String sql "INSERT INTO smsmsg(to, msg,from, timesent)VALUES ('number[i]', 'text', 'from', GETDATE())";
   access.insert(sqli);
}
String sql="";
 for(int i=0;i<numbers.length;i++) {
     sql="INSERT INTO smsmsg (to,msg,from,timesent) VALUES (" 
      + numbers[i] + ",'text','from','12-31-2002')";
     access.insert(sql);
 }
Java Syntax (Toggle Plain Text)

   String sql="";
   for(int i=0;i<numbers.length;i++) {
      sql="INSERT INTO smsmsg (to,msg,from,timesent) VALUES ("
      + numbers[i] + ",'text','from','12-31-2002')";
      access.insert(sql);
    }

I appreciate that this is an old thread but why on earth would you post a reply still with errors and with a pointless fix!.

First of all you are using a reserved word in your SQL statement "from" cannot be used as a parameter as its reserved by SQL.

Secondly whats the point in specifying a date when the Original Poster wanted to get the current date - All that needed to be dones was "& System.DateTime.Now() &"

Please see the amended code below:

Java Syntax (Toggle Plain Text)

   String sql="";
   DateTime dt = DateTime.Now;

   for(int i=0;i<numbers.length;i++) {
      sql="INSERT INTO smsmsg (to,msg,numFrom,timesent) VALUES ("
      & numbers[i] & ",'text','from', " & dt & ")";
      access.insert(sql);
    }

I appreciate that this is an old thread but why on earth would you post a reply still with errors and with a pointless fix!.

First of all you are using a reserved word in your SQL statement "from" cannot be used as a parameter as its reserved by SQL.

Secondly whats the point in specifying a date when the Original Poster wanted to get the current date - All that needed to be dones was "& System.DateTime.Now() &"

Please see the amended code below:

Java Syntax (Toggle Plain Text)

   String sql="";
   DateTime dt = DateTime.Now;

   for(int i=0;i<numbers.length;i++) {
      sql="INSERT INTO smsmsg (to,msg,numFrom,timesent) VALUES ("
      & numbers[i] & ",'text','from', " & dt & ")";
      access.insert(sql);
    }

Your code isn't quite spotless as well. Not to mention that it will not compile.
Apart from using the '&' which is the reason why this is wrong, you go on saying that in order to get the current yo use this: DateTime.Now. And that you should put that into the column the String representation of the DateTime object!
Shouldn't be asking yourself what type is the timesent because in case it is Date and not Varchar (if it is Date your query will not run) you can use an sql function that returns the current date.

Valid point - Funny thing was I actually run into the error you have mentioned just this morning. Date.Now returns the current date and time with / and : symbols which throws an error with SQL.

I am not quite sure why the "&" wouldn't work like you have mentioned? - Although I do code in VB.net and not C# so that could have something to do with it.

Valid point - Funny thing was I actually run into the error you have mentioned just this morning. Date.Now returns the current date and time with / and : symbols which throws an error with SQL.

I am not quite sure why the "&" wouldn't work like you have mentioned? - Although I do code in VB.net and not C# so that could have something to do with it.

This is a java forum. When you post code, try to make sure it runs in java.
Or if you want to help, try to post pseudo code

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.