strong textMy need is 1) I need to create a registration form with 2 inputs. One for user
name and the other for password. 2)The table TaskTable should be created
only once
3)The user name should not be the same for new registration. Please help me to
complete the above code accordingly.
I have the database in the debug folder of my project. The code I have written is
using (SQLiteConnection sqlite_conn = new SQLiteConnection(connectionString))
{
try
{
SQLiteCommand cmd = sqlite_conn.CreateCommand();
sqlite_conn.Open();
1 => cmd.CommandText = "CREATE TABLE TaskTable (UserName varchar(100), PassWord varchar(100));";
cmd.ExecuteNonQuery();
2 => cmd.CommandText = "INSERT INTO TaskTable (UserName,PassWord) values ('" + textBox1.Text + "','" + textBox2.Text + "')";
int i = cmd.ExecuteNonQuery();
if (i == 1)
{
MessageBox.Show("User created successfully....");
}
}
catch (Exception ex)
{
MessageBox.Show("please enter different user name");
}
}
}
}
}
in the code above I have marked => 1 and =>2 where I have issues.
As per => 1, every time I run the project it creates a new table in the
DataBase which is embedded in my project that is in the **debug
folder**.
1) I need the solution as to how to use **if not exists** in the create
table statement, without getting any exception. I mean not just the
CREATE IF NOT EXISTS TABLE TaskTable (UserName varchar(100), PassWord varchar(100));"; ,
but how to use the same properly in try catch block.
2)I find that the table is not stored permanently in the debug folder. I
used SQLite manger added on to MOZILLA fire fox browser to open the data base
folder and I see that once I close the project and browse for the same data base
it does not show the table created earlier.
2 = > the values are inserted into the table only once as every time new table
is created. If i try to comment the create table statement and try to insert
new values it will throw the exception. I think the reason is previous table is deleted. How to make the table exist permanently in the db which is created in the debug folder of the project.
Aucun commentaire:
Enregistrer un commentaire