HelpHandling Local Database

Posts 1–5 of 5 · Page 1 of 1
Handling Local Database
Yeah I know it's C# but I guess it's easy to translate to VB .NET,,,,anyways...I'm trying to store some shit on a local database (Project->New...->Local Database), the point is that I get this error which says that I have to put a vaild Insert Command when calling the function SqlCeDataAdapter.Update()...

Code:
        private string Register(string[] args)
        {
            try
            {
                string user = args[0];
                string password = args[1];
                string dataSource = Environment.CurrentDirectory + "\\protected\\Users.sdf";
                SqlCeConnection connection = new SqlCeConnection("datasource=" + dataSource);
                connection.Open();
                SqlCeDataAdapter adapter = new SqlCeDataAdapter("select * from Users", connection);
                DataSet dataSet = new DataSet();
                adapter.Fill(dataSet);

                int len = dataSet.Tables[0]****ws.Count;
                for (int i = 0; i < len; i++)
                {
                    if (dataSet.Tables[0]****ws[i].ItemArray[0] == user)
                        return "Error: Username is in use.";
                }
                Log.Info("Registering User With:\r\nUsername - " + user + "\r\nID - " + ((len+1) << 54).ToString());
                dataSet.Tables[0]****ws.Add(new object[] { user, password, ((len+1) << 54), 0, 0, 0, "" });
                adapter.Update(dataSet);
                connection.Close();
            }
            catch (Exception ex)
            {
                Log.Error(ex.Message);
            }
            return "User registered!";
        }
If somebody could help me that would be appreciated

http://screensnapr.com/v/xITQaD.png
I recommend using SQLite. And why would you use DataAdapters and DataSets?

Better go for a DataReader and a Command.


(not exact declaration - not sure if those are the exact declaration names)

Code:
Dim Command as new SQLCeCommand("SELECT * FROM Users",conn)

Dim Reader as new SQLCeDataReader

Reader = Command.ExecuteReader()

While Reader.Read()
MsgBox(Reader("Username"))
MsgBox(Reader("Password"))
End While

Reader.Close
Command.Dispose
Code:
Dim Command as new SQLCeCommand("INSERT INTO Users(Username,Password) VALUES('x','y')",conn)

Command.ExecuteNonQuery()
Not fully spoonfeeding you now, just giving you an idea of what you may do.
Quote Originally Posted by Blubb1337 View Post
I recommend using SQLite. And why would you use DataAdapters and DataSets?

Better go for a DataReader and a Command.


(not exact declaration - not sure if those are the exact declaration names)

Code:
Dim Command as new SQLCeCommand("SELECT * FROM Users",conn)

Dim Reader as new SQLCeDataReader

Reader = Command.ExecuteReader()

While Reader.Read()
MsgBox(Reader("Username"))
MsgBox(Reader("Password"))
End While

Reader.Close
Command.Dispose
Code:
Dim Command as new SQLCeCommand("INSERT INTO Users(Username,Password) VALUES('x','y')",conn)

Command.ExecuteNonQuery()
Not fully spoonfeeding you now, just giving you an idea of what you may do.
Well thank you, but I've got that working by myself sometimes ago. Anyways...Can I make you another question? Can I add new lines to a string variable in a row?
Quote Originally Posted by user590177 View Post


Well thank you, but I've got that working by myself sometimes ago. Anyways...Can I make you another question? Can I add new lines to a string variable in a row?
Try something like

UPDATE table set Column=Column & 'Text'

or

UPDATE table set Column=Column + 'Text'

or

UPDATE table set Column=CONCAT(Column,'Text')
Posts 1–5 of 5 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us