Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > Базы данных под .NET > Добавить дату в SQLite


Автор: pokora 1.8.2010, 01:59
Код

SQLiteConnection con = new SQLiteConnection();
            con.ConnectionString = conStr;

            try
            {

                con.Open();

                if (con.State == ConnectionState.Open)
                {
                    MessageBox.Show("Открыто "+DateTime.Now.ToString());
                }


                SQLiteCommand command = new SQLiteCommand();
                command.Connection = con;

                command.CommandText = "Insert into Tovar(Name,Cost,Kol,Date) values('"+tbName.Text+"',"+
                  Convert.ToInt32(tbCost.Text) + "," + Convert.ToInt32(tbKol.Text)  +","
               + DateTime.Now + ");";// вот тут вылетает.
 
                
                
         
                command.ExecuteNonQuery();
                ds.Reset();
                dataAdapter.Fill(ds,"Товары");
                dataGrid1.DataSource =  ds.Tables["Товары"].DefaultView;


что тут не так?


Автор: pokora 1.8.2010, 12:30
решил вот так 
Код

                command.CommandText = "Insert into [Tovar]([Name],[Cost],[Kol],[Date]) values(@Name,@Cost,@Kol,@Date)";
                command.Parameters.AddWithValue("@Name",tbName.Text);
                command.Parameters.AddWithValue("Cost",tbCost.Text);
                command.Parameters.AddWithValue("@Kol",tbKol.Text);
                command.Parameters.AddWithValue("Date", DateTime.Now);

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)