C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




C# and mssql compact problem


Posted Date: 12 Aug 2008      Total Responses: 4

Posted By: matej       Member Level: Bronze     Points: 1



Hi!

i`m new guy here and i have problem with C#. i developing smal application for windows mobile and i try to connect to mssql database(*.sdf), but i get an error when program is trying to connect to database. here is my code. please help!!!

string mstCon = "\\My Documents\\Northwind.sdf";
SqlCeConnection conn = new SqlCeConnection(mstCon);<------------- here is error
conn.Open();
string sql = "select * from Categories";
SqlCeCommand cmd = new SqlCeCommand(sql,conn)

error:
Format of the initialization string does not conform to specification starting at index 0.








Responses

Author: vipul    12 Aug 2008Member Level: DiamondRating:     Points: 4

hi,
you write wrong syntax
you write
string mstCon = "\\My Documents\\Northwind.sdf"; ??? Where to find it
you write this way
string mstCon = "C:\\My Documents\\Northwind.sdf";

you write full path where this database resid.

vipul,
http://dongavipul.blogspot.com




Patel Vipul
Web Developer
Ahmedabad ( Gujarat )



Author: matej    12 Aug 2008Member Level: BronzeRating:     Points: 2

thenks for quickly response.
yes for the computer must be c:\my document.
but for the device i`m not sure that is the correct.



Author: matej    12 Aug 2008Member Level: BronzeRating:     Points: 4

i`ve solve the problem. ther is solution. thanky anyway

SqlCeConnection conn = new SqlCeConnection("Data Source = \\My Documents\\Northwind.sdf; Password =''");
conn.Open();
SqlCeCommand cmd = conn.CreateCommand();
cmd.CommandText = "INSERT INTO test (ID) Values(17)";
cmd.ExecuteNonQuery();



Author: syed shakeer hussain     02 Dec 2008Member Level: GoldRating:     Points: 6

Hi..
I am sending a code

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlServerCe;
namespace HMS
{
public partial class Login : Form
{
public Login()
{
InitializeComponent();
}
SqlCeConnection conn;
SqlCeDataAdapter adapter;
SqlCeCommandBuilder builder;
DataSet ds;





private void btnSingIn_Click_1(object sender, EventArgs e)
{
if (txtuserid.Text != "" && txtpassword.Text != "")
{

if (validcheck())
{
txtuserid.Text = "";
txtpassword.Text = "";
HOMEPAGE obj = new HOMEPAGE();
obj.ShowDialog();
}
else
{
MessageBox.Show("invalid user");
}
}
else MessageBox.Show("Plz Enter UserId and Password");

}

private void btnCancel_Click_1(object sender, EventArgs e)
{
Cursor.Current = Cursors.WaitCursor;
txtpassword.Text = "";
txtuserid.Text = "";
HOSPITALMANAGEMANT obj = new HOSPITALMANAGEMANT();
obj.ShowDialog();
Cursor.Current = Cursors.Default;
}
private bool validcheck()
{
Cursor.Current = Cursors.WaitCursor;
SqlCeConnection conn1 = new SqlCeConnection("DataSource=" + (System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase) + "\\MyDatabase#1.sdf "));

SqlCeCommand cmd = new SqlCeCommand("select userid,password from login where userid='" + txtuserid.Text + "'and password='" + txtpassword.Text + "'", conn1);
SqlCeDataReader reader;
conn1.Open();
reader = cmd.ExecuteReader();
bool valid = false;
while (reader.Read())
{
valid = true;
}
reader.Close();
conn1.Close();
Cursor.Current = Cursors.Default;
return valid;

}

private void Login_Load(object sender, EventArgs e)
{
Cursor.Current = Cursors.WaitCursor;
conn = new SqlCeConnection("DataSource=" + (System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase) + "\\MyDatabase#1.sdf "));
conn.Open();
adapter = new SqlCeDataAdapter("select * from login", conn);
builder = new SqlCeCommandBuilder(adapter);
ds = new DataSet();
adapter.Fill(ds, "login");
conn.Close();
Cursor.Current = Cursors.Default;
}

private void LnkNewuser_Click_1(object sender, EventArgs e)
{
NEW_USER newobj = new NEW_USER();
newobj.ShowDialog();
}

private void label4_ParentChanged(object sender, EventArgs e)
{

}
}
}



Post Reply
You must Sign In to post a response.
Next : How to rename SQLCe database Table name using .Net CF?
Previous : how to identify the mobile device accessing a Web page?
Return to Discussion Forum
Post New Message
Category: Smart Devices

Related Messages



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use