.


:




:

































 

 

 

 


DBConnection DBCommand




DBConnection . . DBCommand ( , SQL ). DBConnection DBCommand DataSet, .

ConnectionString - , .

DataGridView

DataGridView . DataGridView , , DefaultCellStyle, ColumnHeadersDefaultCellStyle, CellBorderStyle GridColor. DataGridView , . , DataGridView Rows Columns. Rows DataGridViewRow, DataGridViewRow.Cells . Item . DataSource DataMember DataGridView .

VirtualMode true, . , DataGridView .

 

 

OleDbCommandBuilder , , DataSet, . .
OleDbConnection .
OleDbConnectionStringBuilder OleDbConnection.
OleDbDataAdapter , DataSet .
OleDbDataReader . .
OleDbEnumerator OLE DB .
OleDbError , , .
OleDbErrorCollection , .NET Framework OLE DB. .
OleDbException , , OLE DB. .
OleDbFactory OLEDB, .
OleDbInfoMessageEventArgs InfoMessage. .
OleDbMetaDataCollectionNames GetSchema .
OleDbMetaDataColumnNames , OleDbMetaDataCollectionNames, DataTable. DataTable GetSchema.
OleDbParameter OleDbCommand DataSet. .
OleDbParameterCollection , OleDbCommand, DataSet.
OleDbPermission .NET Framework OLE DB , OLE DB.
OleDbPermissionAttribute .
OleDbRowUpdatedEventArgs RowUpdated.
OleDbRowUpdatingEventArgs RowUpdating.
OleDbSchemaGuid , GetOleDbSchemaTable.
OleDbTransaction SQL-. .

 

OleDbConnection -

OleDbConnection . - . , OLE DB, OleDbConnection .

OleDbConnection . OleDbConnection DataReader. OLE DB DataReader , .

OleDbConnection , . , Close Dispose OleDbConnection Using.

OleDbException (, SQL Server 20 ) , OleDbCommand, OleDbConnection . , .

, OleDbConnection, . OleDbConnection OleDbPermission. , OleDbPermissionAttribute. , Caspol.exe ( ) , . . ADO.NET.

OleDbCommand OleDbConnection. OleDbConnection Connection OleDbCommand. ExecuteNonQuery, . , ExecuteNonQuery , SQL INSERT.

public void InsertRow(string connectionString, string insertSQL)

{

using (OleDbConnection connection = new OleDbConnection(connectionString))

{

OleDbCommand command = new OleDbCommand(insertSQL);

command.Connection = connection;

try

{

connection.Open();

command.ExecuteNonQuery();

}

catch (Exception ex)

{

Console.WriteLine(ex.Message);

}

}

}

 

 

6

1.

2.

3.

4.

5.

6. .


1) ( : )

2) ( : )

3) ( : )

4) ( : )


1) ( : )

2) ( : )

3) ( : )

4) ( : )

1) ( : )

2) ( : )

3) ( : )

 

1) ( : )

2) ( : )

3) ( : )

4) ( : )

1) ( : )

2) ( : )

3) ( : )

4) ( : )

1) ( : )

2) ( : )

3) ( : )

4) ( : )

5) ( : )

6) ( : )

7) 1 ( : )

8) 1 ( : )

9) 2 ( : )

10) 2 ( : )

11) 3 ( : )

12) 3 ( : )

13) 4 ( : )

14) 4 ( : )

 

 

Microsoft Access.

. 1,

. 1

 

 

 

Form1 (. 2). .

. 2

/// .

. 3

/// .

 

. 4

/// .

. 5

/// .

 

. 6

/// .

 

. 7

/// .

 

. 8 ( )

 


 

1. http://msdn.microsoft.com/ru-RU/

2. http://ru.wikipedia.org/

3. http://www.cyberforum.ru/


4.

Form1

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

 

namespace exam_supa

{

public partial class Form1: Form

{

public Form1()

{

InitializeComponent();

}

 

private void examBindingNavigatorSaveItem_Click(object sender, EventArgs e)

{

this.Validate();

this.examBindingSource.EndEdit();

this.tableAdapterManager.UpdateAll(this.databaseDataSet);

 

}

 

private void Form1_Load(object sender, EventArgs e)

{

// TODO: "databaseDataSet.mark". .

this.markTableAdapter.Fill(this.databaseDataSet.mark);

// TODO: "databaseDataSet.student". .

this.studentTableAdapter.Fill(this.databaseDataSet.student);

// TODO: "databaseDataSet.group". .

this.groupTableAdapter.Fill(this.databaseDataSet.group);

// TODO: "databaseDataSet.spec". .

this.specTableAdapter.Fill(this.databaseDataSet.spec);

// TODO: "databaseDataSet.subject". .

this.subjectTableAdapter.Fill(this.databaseDataSet.subject);

// TODO: "databaseDataSet.exam". .

this.examTableAdapter.Fill(this.databaseDataSet.exam);

 

comboBox1.SelectedIndex = 0;

}

 

enum aTable { Ex, Gr, Mk, Sp, St, Sb, dEx, dSt }

 

private int KeyToIndex(int key, aTable tab)

{

int i;

switch(tab)

{

// exam table

case aTable.Ex:

for(i=0;i<examDataGridView.Rows.Count-1;i++)

{

if(Convert.ToInt32(examDataGridView.Rows[i].Cells[0].Value) == key)

return i;

}

break;

// group table

case aTable.Gr:

for(i=0;i<groupDataGridView.Rows.Count-1;i++)

{

if(Convert.ToInt32(groupDataGridView.Rows[i].Cells[0].Value) == key)

return i;

}

break;

// mark table

case aTable.Mk:

for(i=0;i<markDataGridView.Rows.Count-1;i++)

{

if(Convert.ToInt32(markDataGridView.Rows[i].Cells[0].Value) == key)

return i;

}

break;

// spec table

case aTable.Sp:

for(i=0;i<specDataGridView.Rows.Count-1;i++)

{

if(Convert.ToInt32(specDataGridView.Rows[i].Cells[0].Value) == key)

return i;

}

break;

// student

case aTable.St:

for(i=0;i<studentDataGridView.Rows.Count-1;i++)

{

if(Convert.ToInt32(studentDataGridView.Rows[i].Cells[0].Value) == key)

return i;

}

break;

// subject

case aTable.Sb:

for(i=0;i<subjectDataGridView.Rows.Count-1;i++)

{

if(Convert.ToInt32(subjectDataGridView.Rows[i].Cells[0].Value) == key)

return i;

}

break;

// datagridview1

case aTable.dSt:

for(i=0;i<dataGridView1.Rows.Count-1;i++)

{

if(Convert.ToInt32(dataGridView1.Rows[i].Cells[0].Value) == key)

return i;

}

break;

// datagridview2

case aTable.dEx:

for(i=0;i<dataGridView2.Rows.Count-1;i++)

{

if(Convert.ToInt32(dataGridView2.Rows[i].Cells[0].Value) == key)

return i;

}

break;

}

return -1;

}

 

private void ToolStripMenuItem_Click(object sender, EventArgs e)

{

this.Validate();

this.examBindingSource.EndEdit();

this.tableAdapterManager.UpdateAll(this.databaseDataSet);

}

 

private void tabPage6_Click(object sender, EventArgs e)

{

/*listBox1.Items.Clear();

int i;

for(i=0;i<studentDataGridView.Rows.Count-1;i++)

{

listBox1.Items.Add(studentDataGridView.Rows[i].Cells[1].Value);

}*/

}

 

private void updexam(int group)

{

dataGridView2.Rows.Clear();

int kurs = Convert.ToInt32(groupDataGridView.Rows[group].Cells[3].Value);

int spec = Convert.ToInt32(groupDataGridView.Rows[group].Cells[2].Value);

 

int i, j;

for(i=0;i<subjectDataGridView.Rows.Count-1;i++)

{

if(Convert.ToInt32(subjectDataGridView.Rows[i].Cells[2].Value) == kurs &&

Convert.ToInt32(subjectDataGridView.Rows[i].Cells[3].Value) == spec)

{

int t = Convert.ToInt32(subjectDataGridView.Rows[i].Cells[0].Value);

for(j=0;j<examDataGridView.Rows.Count-1;j++)

{

if(Convert.ToInt32(examDataGridView.Rows[j].Cells[1].Value) == t)

{

dataGridView2.Rows.Add(1);

int k = dataGridView2.Rows.Count-2;

dataGridView2.Rows[k].Cells[0].Value = examDataGridView.Rows[j].Cells[0].Value;

dataGridView2.Rows[k].Cells[1].Value = examDataGridView.Rows[j].Cells[2].Value;

dataGridView2.Rows[k].Cells[2].Value = subjectDataGridView.Rows[i].Cells[1].Value;

dataGridView2.Rows[k].Cells[3].Value = examDataGridView.Rows[j].Cells[3].Value;

}

}

}

}

//MessageBox.Show(group.ToString());

}

 

private void button1_Click(object sender, EventArgs e)

{

dataGridView1.Rows.Clear();

int i;

for(i=0;i<studentDataGridView.Rows.Count-1;i++)

{

dataGridView1.Rows.Add(1);

int j = dataGridView1.Rows.Count-2;

dataGridView1.Rows[j].Cells[0].Value = studentDataGridView.Rows[i].Cells[0].Value;

dataGridView1.Rows[j].Cells[1].Value = studentDataGridView.Rows[i].Cells[1].Value;

dataGridView1.Rows[j].Cells[2].Value = studentDataGridView.Rows[i].Cells[3].Value;

int t = KeyToIndex(Convert.ToInt32(studentDataGridView.Rows[i].Cells[2].Value), aTable.Gr);

dataGridView1.Rows[j].Cells[3].Value = groupDataGridView.Rows[t].Cells[1].Value;

int k = KeyToIndex(Convert.ToInt32(groupDataGridView.Rows[t].Cells[2].Value), aTable.Sp);

dataGridView1.Rows[j].Cells[4].Value = specDataGridView.Rows[k].Cells[1].Value + " ''"+specDataGridView.Rows[k].Cells[2].Value+"''";

dataGridView1.Rows[j].Cells[5].Value = groupDataGridView.Rows[t].Cells[3].Value;

 

for(int l=0;l<4;l++)

{

t = KeyToIndex(Convert.ToInt32(studentDataGridView.Rows[i].Cells[0].Value), aTable.St);

object sb = null;

if(markDataGridView.Rows[t].Cells[1+l*2].Value!= DBNull.Value)

{

k = KeyToIndex(Convert.ToInt32(markDataGridView.Rows[t].Cells[1+l*2].Value), aTable.Ex);

int k1 = KeyToIndex(Convert.ToInt32(examDataGridView.Rows[k].Cells[1].Value), aTable.Sb);

sb = subjectDataGridView.Rows[k1].Cells[1].Value;

}

int mk = 0;

if(markDataGridView.Rows[t].Cells[2+l*2].Value!= DBNull.Value) mk = Convert.ToInt32(markDataGridView.Rows[t].Cells[2+l*2].Value);

dataGridView1.Rows[j].Cells[6+l*2].Value = sb;

dataGridView1.Rows[j].Cells[7+l*2].Value = comboBox1.Items[mk].ToString();

}

}

}

 

private void button2_Click(object sender, EventArgs e)

{

int t = -1, ex = -1;

DataGridViewSelectedRowCollection scc = dataGridView1.SelectedRows;

if(scc!= null && scc.Count > 0)

{

t = KeyToIndex(Convert.ToInt32(scc[0].Cells[0].Value), aTable.St);

}

if(t==-1)

{

MessageBox.Show(" !", "");

return;

}

scc = dataGridView2.SelectedRows;

if(scc!= null && scc.Count > 0)

{

ex = Convert.ToInt32(scc[0].Cells[0].Value);

}

if(ex==-1)

{

MessageBox.Show(" !", "!");

return;

}

 

int mk;

mk = comboBox1.SelectedIndex;

int pos=1;

int i;

for(i=0;i<4;i++)

{

if(markDataGridView.Rows[t].Cells[1+i*2].Value!= DBNull.Value)

{

if(Convert.ToInt32(markDataGridView.Rows[t].Cells[1+i*2].Value) == ex)

{

pos = 1+i*2;

break;

}

}

else

{

pos = 1+i*2;

break;

}

}

 

markDataGridView.Rows[t].Cells[pos].Value = ex;

markDataGridView.Rows[t].Cells[pos+1].Value = mk;

 

button1_Click(this, null);

}

 

private void dataGridView1_SelectionChanged(object sender, EventArgs e)

{

DataGridViewSelectedRowCollection scc = dataGridView1.SelectedRows;

if(scc!= null && scc.Count > 0)

{

int t = KeyToIndex(Convert.ToInt32(scc[0].Cells[0].Value), aTable.St);

if(t!=-1)

{

int g = KeyToIndex(Convert.ToInt32(studentDataGridView.Rows[t].Cells[2].Value), aTable.Gr);

updexam(g);

}

}

}

 

private void Form1_FormClosed(object sender, FormClosedEventArgs e)

{

this.Validate();

this.examBindingSource.EndEdit();

this.tableAdapterManager.UpdateAll(this.databaseDataSet);

}

 

private bool StringAsInt(string str)

{

char[] toa = str.ToCharArray();

for(int i=0;i<str.Length;i++)

{

if(toa[i] < (int)'0' || toa[i] > (int)'9')

return false;

}

return true;

}

 

private void button3_Click(object sender, EventArgs e)

{

if(textBox1.Text == "" || textBox2.Text == "" ||

comboBox2.SelectedIndex == -1)

{

MessageBox.Show(" !", "!");

return;

}

 

if(StringAsInt(textBox2.Text))

{

int t = Convert.ToInt32(textBox2.Text);

if(t<1 || t>groupDataGridView.Rows.Count-1)

{

MessageBox.Show(" : "+t.ToString()+"!", "");

return;

}

}

else

{

MessageBox.Show(" '' ''!", "");

return;

}

 

studentBindingSource.AddNew();

int k = studentDataGridView.Rows.Count-2;

studentDataGridView.Rows[k].Cells[1].Value = textBox1.Text;

studentDataGridView.Rows[k].Cells[2].Value = textBox2.Text;

studentDataGridView.Rows[k].Cells[3].Value = comboBox2.SelectedItem.ToString();

 

}

 

private void studentDataGridView_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)

{

markBindingSource.AddNew();

}

 

private void toolStripMenuItem1_Click(object sender, EventArgs e)

{

DataGridViewSelectedRowCollection scc = studentDataGridView.SelectedRows;

if(scc!= null && scc.Count > 0)

{

int key = Convert.ToInt32(scc[0].Cells[0].Value);

int i;

for(i=0;i<studentDataGridView.Rows.Count-1;i++)

{

if(Convert.ToInt32(studentDataGridView.Rows[i].Cells[0].Value) == key)

{

studentBindingSource.RemoveAt(i);

markBindingSource.RemoveAt(i);

return;

}

}

}

}

 

private void toolStripMenuItem2_Click(object sender, EventArgs e)

{

DataGridViewSelectedRowCollection scc = examDataGridView.SelectedRows;

if(scc!= null && scc.Count > 0)

{

int key = Convert.ToInt32(scc[0].Cells[0].Value);

int i = KeyToIndex(key, aTable.Ex);

int j, l;

for(j=0;j<markDataGridView.Rows.Count-1;j++)

{

for(l=0;l<4;l++)

{

if(markDataGridView.Rows[j].Cells[1+l*2].Value!= DBNull.Value)

{

if(Convert.ToInt32(markDataGridView.Rows[j].Cells[1+l*2].Value) == key)

{

markDataGridView.Rows[j].Cells[1+l*2].Value = DBNull.Value;

markDataGridView.Rows[j].Cells[2+l*2].Value = DBNull.Value;

}

}

}

}

examBindingSource.RemoveAt(i);

}

}

 

private void toolStripMenuItem3_Click(object sender, EventArgs e)

{

DataGridViewSelectedRowCollection scc = subjectDataGridView.SelectedRows;

bool t=false;

if(scc!= null && scc.Count > 0)

{

int key = Convert.ToInt32(scc[0].Cells[0].Value);

int i = KeyToIndex(key, aTable.Sb);

int j;

for(j=0;j<examDataGridView.Rows.Count-1;j++)

{

if(examDataGridView.Rows[j].Cells[1].Value!= DBNull.Value)

{

if(Convert.ToInt32(examDataGridView.Rows[j].Cells[1].Value) == key)

{

t = true;

}

}

}

if(t)

{

MessageBox.Show(" , !", "");

}

else

{

subjectBindingSource.RemoveAt(i);

}

}

}

 

private void toolStripMenuItem4_Click(object sender, EventArgs e)

{

DataGridViewSelectedRowCollection scc = specDataGridView.SelectedRows;

if(scc!= null && scc.Count > 0)

{

bool t = false;

int key = Convert.ToInt32(scc[0].Cells[0].Value);

int i = KeyToIndex(key, aTable.Sp);

int j;

for(j=0;j<groupDataGridView.Rows.Count-1;j++)

{

if(groupDataGridView.Rows[j].Cells[2].Value!= DBNull.Value)

{

if(Convert.ToInt32(groupDataGridView.Rows[j].Cells[2].Value) == key)

{

t = true;

}

}

}

if(t)

{

MessageBox.Show(" , () ()!","");

}

else

{

specBindingSource.RemoveAt(i);

}

}

}

 

private void ToolStripMenuItem_Click(object sender, EventArgs e)

{

DataGridViewSelectedRowCollection scc = groupDataGridView.SelectedRows;

if(scc!= null && scc.Count > 0)

{

bool t = false;

int key = Convert.ToInt32(scc[0].Cells[0].Value);

int i = KeyToIndex(key, aTable.Gr);

int j;

for(j=0;j<groupDataGridView.Rows.Count-1;j++)

{

if(studentDataGridView.Rows[j].Cells[2].Value!= DBNull.Value)

{

if(Convert.ToInt32(studentDataGridView.Rows[j].Cells[2].Value) == key)

{

t = true;

}

}

}

if(t)

{

MessageBox.Show(" , () ()!","");

}

else

{

groupBindingSource.RemoveAt(i);

}

}

}

}

}

 

 





:


: 2017-02-24; !; : 443 |


:

:

, .
==> ...

1509 - | 1276 -


© 2015-2024 lektsii.org - -

: 0.331 .