split - OLE DB command in visual C# for splitting serial data -


i have problem on how split data serial port , save access database designated column. found example written in vb.net cannot find example code written in c#. serial data this:

,230,302

,230,302

and continuously.

this have written far:

void sp_datareceived(object sender, serialdatareceivedeventargs e)     {         thread.sleep(1000);         string[] data = _serialport.readexisting().split(',');         oledbconnection connect = new oledbconnection();         connect.connectionstring = @"provider=microsoft.ace.oledb.12.0;data source=c:\users\xp\desktop\hydrodatabase.accdb";         connect.open();         oledbcommand command = new oledbcommand();         command.commandtext = "insert hydrolog(waterflow,turbinerpm) values(@data1, @data2)", connect);      } 

you need use using statement dispose of resources. string split produce empty entry @ beginning, try use stringsplitoptions.

const string connectionstring = @"provider=microsoft.ace.oledb.12.0;data source=c:\users\xp\desktop\hydrodatabase.accdb"; const string commandtext = "insert hydrolog(waterflow,turbinerpm) values(@data1, @data2)";  string[] data = _serialport.readexisting().split(new[] { ',' }, stringsplitoptions.removeemptyentries);  using(var connect = new oledbconnection(connectionstring)) {     using(var command = new oledbcommand(commandtext, connect))     {         command.parameters.addwithvalue("@data1", data[0]);         command.parameters.addwithvalue("@data2", data[1]);          connect.open();         command.executenonquery();     } } 

Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -