- Home /
Question by
lloladin · May 28, 2015 at 11:09 AM ·
c#visualstudiosqldatabase
Visual studio Database
so im wondering how connect to my database in Visual studio with unity i alryd know advanced Asp.net #C and how to do it for web but not quite sure how i have to write my connecting string code when its for unity like whats the difrence like normally when i make databases i have a webconfig so when i use untiy what do i have to do instead or is it just the same?
this is how i usally do it for web
SqlConnection conn = new SqlConnection(); // sql connect
conn.ConnectionString = ConfigurationManager.ConnectionStrings["DatabaseConnectionString1"].ToString();
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
// SQL strengen
//cmd.CommandText = "INSERT INTO service_tb (service_title, service_text, fk_billed_id) VALUES (@title, @text, @billed)";
cmd.CommandText = "INSERT INTO login_tb (login_user, login_pass, login_fornavn, login_efternavn, login_adresse, login_email, fk_rolle_id) VALUES (@user, @pass, @fornavn, @efternavn, @adresse, @email, 1)";
// Tilføj parametrer (input fra TextBoxe fra .aspx siden) til din SQL streng ovenover
cmd.Parameters.Add("@user", SqlDbType.NVarChar).Value = login_user_insert.Text;
cmd.Parameters.Add("@pass", SqlDbType.NVarChar).Value = login_pass_insert.Text;
cmd.Parameters.Add("@fornavn", SqlDbType.NVarChar).Value = login_fornavn_insert.Text;
cmd.Parameters.Add("@efternavn", SqlDbType.NVarChar).Value = login_efternavn_insert.Text;
cmd.Parameters.Add("@adresse", SqlDbType.NVarChar).Value = login_adresse_insert.Text;
cmd.Parameters.Add("@email", SqlDbType.NVarChar).Value = login_email_insert.Text;
conn.Open();
SqlDataReader reader = cmd.ExecuteReader();
conn.Close();
Response.Redirect("admin.aspx?adminlogin=insert");
this is an insert from one of my projects
Comment
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Compiling C# in Visual Studio? 1 Answer
Creating new C# script in unity not being added in VS's solution 3 Answers