okay so im new to database im still learning so my sql local database is working fine on my pc where im using visual studio 2012 whenever i move the file to open my project on my college's pc or laptop i cant seem to get the database connected since the connection string for that pc is different where i need to manually change my string is there easy solution for this? help needed.
to make it work i had to manually string it everytime
public partial class adminLogin : System.Web.UI.Page { SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\UsersSuren\Documents\Visual Studio 2012\Projects\Shopee mobile\Shopee mobile\App_Data\shopping.mdf;Integrated Security=True"); int i; protected void Page_Load(object sender, EventArgs e) {} protected void b1_Click(object sender, EventArgs e) { con.Open(); SqlCommand cmd = con.CreateCommand(); cmd.CommandText = "select * from admin_login where username='"+t1.Text+"' and password='"+t2.Text+"'"; cmd.ExecuteNonQuery(); DataTable dt = new DataTable(); SqlDataAdapter da = new SqlDataAdapter(cmd); da.Fill(dt); i = Convert.ToInt32(dt.Rows.Count.ToString()); if (i == 1) { Response.Redirect("testing.aspx"); } else { l1.Text = "Invalid password or username"; } con.Close(); }
}
#c-sharp #asp.net