|
I think you should execute the command afther you add the parameters to it, or else the insert will fail (as it has so far) havning nothing to insert.
Something like this:
private void menuItem4_Click(object sender, EventArgs e) {
string wCS = @"Data Source =\Storage Card\ModeDifféré\BaseGmaoLocale.sdf;";
SqlCeConnection sqlceconn = new SqlCeConnection(wCS);
SqlCeCommand command2 = sqlceconn.CreateCommand();
command2.CommandText = "INSERT INTO compteurs2 ([com], [quantite],[datequantite] ) Values(@com,@qtte,SYSDATE)";
SqlCeParameter com = new SqlCeParameter("@com", SqlDbType.NVarChar);
com.Value = comComboBox.SelectedItem.ToString();
command2.Parameters.Add(com);
SqlCeParameter qtte = new SqlCeParameter("@qtte", SqlDbType.Float);
qtte.Value = float.Parse(textBox1.Text);
command2.Parameters.Add(qtte);
command2.ExecuteNonQuery();
}
Oh and, I an not 100% sure, but I think that SYSDATE is not supported in SQL CE, the one that should work is GETDATE() .
I have no smart signature yet...
|
|
|
|
|
thank you for your suggestion but it still doesn't work.
|
|
|
|
|
What is the code you run now and what si the result (any exceptions?).
I have no smart signature yet...
|
|
|
|
|
this is the code:
private void menuItem4_Click(object sender, EventArgs e)
{
DateTime t = DateTime.Now;
string wCS = @"Data Source =\Storage Card\ModeDifféré\BaseGmaoLocale.sdf;";
SqlCeConnection sqlceconn = new SqlCeConnection(wCS);
SqlCeCommand command2 = sqlceconn.CreateCommand();
command2.CommandText = "INSERT INTO compteurs2 ([com], [quantite],[datequantite] ) Values(@com,@qtte,@dat)";
SqlCeParameter com = new SqlCeParameter("@com", SqlDbType.NVarChar);
com.Value = comComboBox.SelectedItem.ToString();
command2.Parameters.Add(com);
SqlCeParameter qtte = new SqlCeParameter("@qtte", SqlDbType.Float);
qtte.Value = float.Parse(textBox1.Text);
command2.Parameters.Add(com);
SqlCeParameter dat = new SqlCeParameter("@dat", SqlDbType.Float);
dat.Value = t;
command2.Parameters.Add(dat);
command2.ExecuteNonQuery();
}
and i didn't see any exception.
|
|
|
|
|
I think that:
a) you connection is not opened
b) yout command is not attached to that connection
c) adding twice the com parameter does not solve anything
d) the @dat parameter should by datetime
Most probably this code should work:
private void menuItem4_Click(object sender, EventArgs e)
{
string wCS = @"Data Source =\Storage Card\ModeDifféré\BaseGmaoLocale.sdf;";
using(SqlCeConnection sqlceconn = new SqlCeConnection(wCS))
{
string insertString = "INSERT INTO compteurs2 ([com], [quantite],[datequantite] ) Values(@com,@qtte,@dat)";
SqlCeCommand command2 = sqlceconn.CreateCommand(insertString, sqlceconn);
SqlCeParameter com = new SqlCeParameter("@com", SqlDbType.NVarChar);
SqlCeParameter qtte = new SqlCeParameter("@qtte", SqlDbType.Float);
SqlCeParameter dat = new SqlCeParameter("@dat", SqlDbType.DateTime);
com.Value = comComboBox.SelectedItem.ToString();
qtte.Value = float.Parse(textBox1.Text);
dat.Value = DateTime.Now;
command2.Parameters.Add(com);
command2.Parameters.Add(qtte);
command2.Parameters.Add(dat);
command2.Connection.Open();
command2.ExecuteNonQuery();
}
}
I have no smart signature yet...
|
|
|
|
|
thank you but for the line:
SqlCeCommand command2 = sqlceconn.CreateCommand(insertString,sqlceconn);
the following error occurs:
Error 1 No overload for method 'CreateCommand' takes '2' arguments C:\Users\Admin\Documents\Visual Studio 2008\Projects\GMAOMobile\ModeDifféré\Energie.cs 107 41 ModeDifféré
what is the problem?
|
|
|
|
|
My bad, try
SqlCeCommand command2 = sqlceconn.CreateCommand();
command2.CommandText = insertString;
or
SqlCeCommand command2 = new SqlCeCommand(insertString,sqlceconn);
Both do the same thing.
I have no smart signature yet...
|
|
|
|
|
the error was repaired but nothing happened in data base. There is is no line inserted.
|
|
|
|
|
How do you check if your line has been inserted?
I have no smart signature yet...
|
|
|
|
|
i open the table from visual studio after closing the application and i check if there is a new line inserted.
|
|
|
|
|
Most probably the table opened from visual studio is just a local copy of the database file.
Your operation is made on the smart device simulator, on that database. You can download the file from the smart device and check the row is inserted, or you can execute a select command on the device to check the row count.
I have no smart signature yet...
|
|
|
|
|
|
Sr...Frank wrote: Please let me know right code.
By this you mean, write code for me. No. You have a list of the child windows, iterate through them and close.
If you have tried and need help, then post what you have tried and ask.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
private void button2_Click(object sender, EventArgs e)
{
foreach (Form2 f in this.MdiChildren)
{
f.Dispose();
}
}
|
|
|
|
|
|
please don't remove messages, it is against the forum guidelines.
|
|
|
|
|
Please don't feed the idiots.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Hi Guys,
I wish for the first line of my DataGridView to be a search line, meaning that all the other rows are filtered according to the value the user inserts to the corresponding column top cell. For example, if the user enters "a*" at the first row's first cell, only rows with the first cell beginning with the letter "a" are shown. Of course, when sorting, this line should be disregarded.
Any suggestions of how to implement such functionality?
Thanks!
Eyal.
|
|
|
|
|
Hi,
I try to develop a csharp smart device application.I want to try the RDA method to connect to the database .mdf located in my collegue'sPC
My code is like that:
using System;
using System.Linq;
using System.Data.SqlServerCe;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace ModeDifféré
{
public partial class Form6 : Form
{
public Form6()
{
InitializeComponent();
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void Form6_Load(object sender, EventArgs e)
{
string sConnection = "Data Source=Bacem-PC;User ID=sa;Password=sa;Initial Catalog=GMAO;Persist Security Info=false;";
string sSQL = "SELECT Nbt FROM 4BT; ";
SqlConnection conn = new SqlConnection(sConnection);
SqlCommand comm = new SqlCommand(sSQL, conn);
SqlDataReader dr = null;
try
{
comm.Connection.Open();
dr = comm.ExecuteReader();
while (dr.Read())
comboBox1.Items.Add(dr[0]);
}
catch (SqlException ex)
{
MessageBox.Show("connexion impossible");
MessageBox.Show(ex.Message);
return;
}
dr.Close();
comm.Connection.Close();
}
}
}
where bacem-PC is my freind'sPC server .He enables remote connexion to his sql server.
When running,this error appears:"specified sql server not found or acces denied"
As a note,this is the same arror that appears when I try locally in my PC
I am really fed up of this annoying error??
URGENT HELP I NEED or i will be a mad person
Thanks
|
|
|
|
|
Funny thing...
Afther a whole thread in which I tried to solve your problem but did not succed you are not demoralised and still prospecting for new solutions...
I like your persistence
You previously said that Visual Studio and Management Studio can connect to your database. If so: add a dataset to your project, and from Visual Studio's datasources (usualy in the left of the screen) drag your tables onto the dataset. This will generate code that connects to your database retrives rows and can update them. (If you don't know how to use this google for Dataset and Strongly Typed Dataset ).
I have no smart signature yet...
|
|
|
|
|
Hi Vlad,
When I have a problem,I don't be happy only if I solve it with all kinds of problems
The problem,Vlad,is that the database I want to connect to is is .mdf database and not .sdf file(used in mobile applications).I want to clarify to u that my project has an object to help the technician communicates successfully with his society'sdatabase.In fact,This society has a .mdf databse created with sql server.The technician will communicate with it with his PDA or his mobile.So that is why I try to connect to my freind'sPC server simulating the process I described above.
If i will add a dataset like u said,I really don't understand to drag tables of .mdf database and use them like .sdf one because in visual studio smart device application doesn't accept only .sdf database files.
I seem sometimes very curious but really I want to demonstrate to all that Marwen can deal well very diffucult problems
Thanks for u collaboration.
|
|
|
|
|
So you are saying that this is a smart device application?
If so, then probably your smart device simulator is not in the same network (if any) with you database server. You might want to check this link[^].
I have no smart signature yet...
|
|
|
|
|
Hi,
Thanks I check the link but almost for the steps I did.But nothing is new
I need really urgent help
Thanks
|
|
|
|
|
Hi Vlad,
Finally I depass the problem of the connexion to server by the DB File's attachment . No exception apperas.Still now the problem of the filling of my combobox .I try with sqldataset instead of the sqlreader like this:
string sConnection = "Data Source=127.0.0.1,1433;Persist Security Info=True;Initial Catalog=GMAO;User ID=sa;Password=sa";
string sSQL = "SELECT com FROM energie; ";
SqlConnection conn = new SqlConnection(sConnection);
SqlCommand comm = new SqlCommand(sSQL, conn);
DataSet ds = new DataSet();
SqlCeDataAdapter da = new SqlCeDataAdapter();
SqlDataReader dr = null;
try
{
comm.Connection.Open();
da.Fill(ds, "SQL Temp Table");
foreach(DataRow d in ds.Tables[0].Rows)
comboBox1.Items.Add(d.ToString());
}
catch (SqlException ex)
{
MessageBox.Show(ex.Message);
return;
}
dr.Close();
comm.Connection.Close();
}
but nothing is added to my combobox.
Thanks in all cases for u collaboration
I am really so happy
|
|
|
|
|
Hi All,
Im developing a POS application as part of a personal project. The project has a Datagridview which has the items being sold (Quantity,Item Name, Price etc). The Datagridview is on the left of the screen and on the bottom right is my virtual keypad which is basically just a series of Buttons, one for each number. The rest of teh screen is made up of various buttons indicating stock items to sell.
Im having problems getting my head around how to modify a value in the datagrid using the on screen Keyboard. If I click on the button wont focus be taken away from teh Datgridview cell i want to edit?
For example I want the user to click in the Quantity Row on the datgrid and it selects (highlights) what is currently in there (1 For Example) and then if I hit the "2" Button it replaces the 1 with a 2.
Any assistance would be greatly appreciated.
Thanks,
Daniel.
|
|
|
|