forked from CxCE/Exercises
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconnectionstringi.aspx.cs
42 lines (36 loc) · 1.15 KB
/
connectionstringi.aspx.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
namespace CxCE_Demo
{
public partial class connectionstringi : System.Web.UI.Page
{
protected void submit_Click(object sender, EventArgs e)
{
getName(name.Text);
}
private void getName(string database)
{
string username = "No name";
SqlConnection conn = new SqlConnection("Server=myServerAddress;Database=" + database + ";User Id=myUsername;Password=" + Constants.DB_PASSWORD + ";");
SqlCommand cmd = new SqlCommand();
SqlDataReader reader;
cmd.CommandText = "SELECT NAME FROM Users WHERE ID = 1000;";
cmd.CommandType = CommandType.Text;
cmd.Connection = conn;
conn.Open();
reader = cmd.ExecuteReader();
if (reader.HasRows)
{
username = reader["NAME"].ToString();
}
message.Text = "Welcome " + username;
conn.Close();
}
}
}