TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Dipa Ahuja
NA
3.1k
714.3k
sql error: cannot open database
Jan 21 2010 12:37 PM
hi... i m getting error like this in my code
public partial class items : Form
{
string con = "Server=.\\SQLEXPRESS;Database=|DataDirectory|/db1.mdf;Trusted_Connection=True;";
SqlDataAdapter da = new SqlDataAdapter();
SqlConnection objconnection;
private void btnshow_Click(object sender, EventArgs e)
{
objconnection = new SqlConnection(con);
objconnection.Open();
<-------ERROR
string ss=comboBox1.SelectedValue.ToString();
string q = "select * from items where cname= " + "'" + ss.ToString() + "'";
SqlCommand comm = new SqlCommand("select * from items where cname=@cname", objconnection);
comm.Parameters.AddWithValue("@cname", ss.ToString());
comm.ExecuteNonQuery();
textBox1.Text = comboBox1.SelectedValue.ToString();
da = new SqlDataAdapter(q, con);
DataSet ds = new DataSet();
da.Fill(ds);
dataGrid1.DataSource = ds.Tables[0];
}
Error
Cannot open database "|DataDirectory|/db1.mdf" requested by the login. The login failed.
Login failed for user 'AHUJA-2FD08D31D\Ahuja's'.
Reply
Answers (
6
)
Updating a form1 when manipulating the form2 data.
Shopping Cart Using c# and SQL server