<< >>


4.3.4.

 

. ( 13), , , Windows-. ( 14), , - .

Windows-, . 93.

:

string connectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=" +
@"D:\BM\For ADO\BDTur_firmSQL2.mdf" +
"Integrated Security=True;Connect Timeout=30;User Instance=True";

Connection Command, , Parameters:

private void btnRun_p1_Click(object sender, System.EventArgs e) {
SqlConnection conn = new SqlConnection();
conn.ConnectionString = connectionString;
SqlCommand myCommand = conn.CreateCommand();
myCommand.CommandType = CommandType.StoredProcedure;
myCommand.CommandText = "[proc_p1]";
string FamilyParameter = Convert.ToString(txtFamily_p1.Text);
 
myCommand.Parameters.Add("@", SqlDbType.NVarChar, 50);
myCommand.Parameters["@"].Value = FamilyParameter;
conn.Open();
SqlDataReader dataReader = myCommand.ExecuteReader();
while (dataReader.Read()) {
// , dataReader,
// Get
int TouristID = dataReader.GetInt32(0);
string Family = dataReader.GetString(1);
string FirstName = dataReader.GetString(2);
string MiddleName = dataReader.GetString(3);
// lbResult_p1
lbResult_p1.Items.Add(" : " + TouristID+ " : " + Family + " : "+ FirstName + " : " + MiddleName);
}
conn.Close();
} // btnRun_p1_Click
 
private void btnRun_p5_Click(object sender, System.EventArgs e) {
SqlConnection conn = new SqlConnection();
conn.ConnectionString = connectionString;
SqlCommand myCommand = conn.CreateCommand();
myCommand.CommandType = CommandType.StoredProcedure;
myCommand.CommandText = "[proc_p5]";
string NameTourParameter = Convert.ToString(txtNameTour_p5.Text);
double KursParameter = double.Parse(this.txtKurs_p5.Text);
myCommand.Parameters.Add("@nameTour", SqlDbType.NVarChar, 50);
myCommand.Parameters["@nameTour"].Value = NameTourParameter;
myCommand.Parameters.Add("@", SqlDbType.Float, 8);
myCommand.Parameters["@"].Value = KursParameter;
conn.Open();
int UspeshnoeIzmenenie = myCommand.ExecuteNonQuery();
if (UspeshnoeIzmenenie !=0) {
MessageBox.Show(" ", " ");
}
else {
MessageBox.Show(" ", " ");
}
conn.Close();
}
 
private void btnRun_proc6_Click(object sender, System.EventArgs e) {
SqlConnection conn = new SqlConnection();
conn.ConnectionString = connectionString;
SqlCommand myCommand = conn.CreateCommand();
myCommand.CommandType = CommandType.StoredProcedure;
myCommand.CommandText = "[proc6]";
conn.Open();
string MaxPrice = Convert.ToString(myCommand.ExecuteScalar());
lblPrice_proc6. Text = MaxPrice;
conn.Close();
}

93-95.

. 93. proc_p1

. 94. proc_p5

. 95. proc_p6

 

 

(. 15). Windows- , 96.

. 96.

Connection:

SqlConnection conn = null;

btnRun :

private void btnRun_Click(object sender, System.EventArgs e) {
try {
conn = new SqlConnection();
conn.ConnectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=" +
@"D:\BM\For ADO\BDTur_firmSQL2.mdf +
"Integrated Security=True;Connect Timeout=30;User Instance=True";
SqlCommand myCommand = conn.CreateCommand();
myCommand.CommandType = CommandType.StoredProcedure;
myCommand.CommandText = "[proc_po1]";
int TouristID = int.Parse(this.txtTouristID.Text);
myCommand.Parameters.Add("@TouristID", SqlDbType.Int, 4);
myCommand.Parameters["@TouristID"].Value = TouristID;
// , .. .
//myCommand.Parameters["@TouristID"].Direction = ParameterDirection.Input;
myCommand.Parameters.Add("@LastName", SqlDbType.NVarChar, 60);
myCommand.Parameters["@LastName"].Direction = ParameterDirection.Output;
conn.Open();
myCommand.ExecuteScalar();
lblFamily.Text = Convert.ToString(myCommand.Parameters["@LastName"].Value);
}
catch (Exception ex) {
MessageBox.Show(ex.ToString());
} finally {
conn.Close();
}
}

@LastName Parameters, output Direction:

myCommand.Parameters["@LastName"].Direction = ParameterDirection.Output;

@TouristID , Direction Input. Parameters, . , , InputOutput, , , - ReturnValue.

97.

. 97.

 

SQL-

 

SQL-, . , . proc_NextResult. proc_NextResult : , - :

CREATE PROCEDURE proc_NextResult
AS
SET NOCOUNT ON
SELECT * FROM
SELECT * FROM
RETURN

Windows-.

ListBox, Dock Bottom. Splitter (), Dock Bottom. , ListBox, Dock Fill.

: ListBox , - .

:

public Form1() {
InitializeComponent();
SqlConnection conn = new SqlConnection();
conn.ConnectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=" +
@"D:\\For ADO\BDTur_firmSQL2.mdf" +
"integrated Security=True;Connect Timeout=30;User Instance=True";
SqlCommand myCommand = conn.CreateCommand();
myCommand.CommandType = CommandType.StoredProcedure;
myCommand.CommandText = "[proc_NextResult]";
conn.Open();
SqlDataReader dataReader = myCommand.ExecuteReader();
while(dataReader.Read()) {
listBox2.Items.Add(dataReader.GetString(1)+" "+dataReader.GetString(2));
}
dataReader.NextResult();
while(dataReader.Read()) {
listBox1.Items. Add(dataReader.GetString(1) +
". : "+dataReader.GetString(3));
}
dataReader.Close();
conn.Close();
}

98.

. 98.

 



<< >>