Click here to Skip to main content
15,887,344 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL

while i run the below code it will not open the connection some time show error in Connection String also show error of Path provided by system in not correct


using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlServerCe;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Master
{
public partial class Form1 : Form
{

public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{

}

private void tx1_TextChanged(object sender, EventArgs e)
{

}

private void tx2_TextChanged(object sender, EventArgs e)
{

}

private void sn_Click(object sender, EventArgs e)
{

SqlCeConnection conn = new SqlCeConnection();
conn.ConnectionString ="Data Source=C:\\Projects\\Master\\Master\\sanjay.sdf";

conn.Open();
//SqlCeDataReader dr = null;
SqlCeCommand cmd = new SqlCeCommand("INSERT INTO emp(usid,pass) VALUES (@us,@id)",conn);
cmd.Parameters.Add(new SqlCeParameter("@ns", tx1.Text));
cmd.Parameters.Add(new SqlCeParameter("@id", tx2.Text));
//qw.Open();
cmd.ExecuteNonQuery();
conn.Close();
MessageBox.Show("Insert Data Sucessfully");
tx1.Text = "";
tx2.Text = "";

}

private void can_Click(object sender, EventArgs e)
{
Application.Exit();

}
}
}
Posted

 
Share this answer
 
Comments
Anoop India 31-Aug-13 3:07am    
i will right click on my Data Base and select property ,and copy the connection String
as
Data Source=C:\Projects\Master\Master\mono.sdf

show can you tell me that it is in proper way or not
Check your connection string
 
Share this answer
 
Comments
Anoop India 31-Aug-13 3:01am    
can u tell me the proper Format of Connection String
manikjeyam 31-Aug-13 3:06am    
Windows Authntication
Data source="Server Name=your servername; Initial Catalog=Db name Integrate security='True"

server Authuntication
Data source="Server Name=your servername; Initial Catalog=Db name ;UId='username';Pwd=pwd"

Anoop India 31-Aug-13 3:13am    
i will right click on my Data Base and select property ,and copy the connection String as Data Source=C:\Projects\Master\Master\mono.sdf show can you tell me that it is in proper way or not
Anoop India 31-Aug-13 3:15am    
i wanted to connect SqlCe data base which is compact 3.5 addition of sql
manikjeyam 31-Aug-13 3:20am    
I think your using mdf file right?
Suppose using mdf file mean you can restore mdf file in databse after give you connection string
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900