mandag 25. mai 2009

http://www.codeproject.com/KB/database/sql_in_csharp.aspx

Example:
Provider=sqloledb;Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;

myServerAddressm would be the IP of the server.myDataBase would be the name of the database on the server.myUsername and myPassword would be the user account in the database server.

http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Studio_.NET_2005/Q_23016900.html
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["SecurityServerConnStr"]);

and your config should be the following





http://www.experts-exchange.com/Microsoft/Development/Visual_Studio_Express/Q_24167406.html

torsdag 21. mai 2009

SELECT * FROM saker Where dato Between '04.05.2009' and'10.05.2009'

SELECT* FROM saker Where dato Between '04.05.2009' and'10.05.2009' AND brukernavn = 'glennj'

SELECT * FROM saker Where dato Between '04.05.2009' and'10.05.2009' AND brukernavn = 'glennj' OR brukernavn = 'henrya'

------------------
SELECT antallnye + antallgamle FROM saker Where dato Between '04.05.2009' and'10.05.2009' AND brukernavn = 'glennj' OR brukernavn = 'henrya'

-------------------------------

funker ikke
SELECT antallnye + antallgamle, (select antallgamle FROM saker Where dato Between '04.05.2009' and'05.05.2009' AND brukernavn = 'glennj') FROM saker Where dato Between '04.05.2009' and'05.05.2009' AND brukernavn = 'glennj'

SELECT (antallnye + antallgamle - (select antallnye FROM saker Where dato = '05.19.2009') ), dato FROM saker Where brukernavn = 'glennj' AND dato = '05.18.2009'

data =
______________antallnye___antallgamle_______løst
18.05.2009______6________9_______________4
19.05.2009 _____11________5_______________-4

20.05.2009 _____20_______11_______________


funker
--------------------------------
SELECT brukernavn, (antallnye + antallgamle - (select antallnye FROM saker Where dato = '05.19.2009' AND brukernavn = 'glennj' ) )as løst, dato FROM saker Where brukernavn = 'glennj' AND dato = '05.18.2009'
--------------------------------

ny spørring
---------------------------------
SELECT brukernavn, (antallnye + antallgamle - (select antallnye FROM saker Where dato = '05.19.2009' AND brukernavn = 'glennj' ) )as løst, dato FROM saker Where brukernavn = 'glennj' or brukernavn = ' henrya 'AND dato = '05.18.2009'

resultalt

GLENNJ418.05.2009

GLENNJ519.05.2009

GLENNJ1920.05.2009




-------------------------------------------

Bruker IN funker må ha IN verdi inni ( )

SELECT brukernavn, (antallnye + antallgamle - (select antallnye FROM saker Where dato IN ('05.19.2009') AND brukernavn IN ('glennj') ) )as løst, dato FROM saker Where brukernavn IN ('glennj') AND dato IN ('05.18.2009')

------------------------------------------

tirsdag 19. mai 2009

private void button39_Click(object sender, EventArgs e)
{

DialogResult result = MessageBox.Show("vil du legge data in i Database?", "ja eller nei", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);

if (result == DialogResult.Yes)
{
MessageBox.Show("Da er det lagret!!");
}
else if (result == DialogResult.No)
{
MessageBox.Show("Ikke savet!!");
}

søndag 17. mai 2009

add binding source
dbBindingSource = bindnge source1
dbGridview = grid1

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;
using System.Data.SqlClient;
namespace database_v3
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
string strCon = "Data Source=.\\SQLEXPRESS;AttachDbFilename=DataDirectory\\sakerDB.mdf;Integrated Security=True;User Instance=True";
string strSQL = "SELECT Brukernavn, antallnye + antallall AS Expr1, Dato FROM test_1";
SqlDataAdapter dataAdapter = new SqlDataAdapter(strSQL, strCon);
SqlCommandBuilder commandBuilder = new SqlCommandBuilder(dataAdapter);
// Populate a new data table and bind it to the BindingSource.
DataTable table = new DataTable();
table.Locale = System.Globalization.CultureInfo.InvariantCulture;
dataAdapter.Fill(table);
dbBindSource.DataSource = table;
// Resize the DataGridView columns to fit the newly loaded content.
dbGridView.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader);
// finally bind the data to the grid
dbGridView.DataSource = dbBindSource;
}
private void button1_Click(object sender, EventArgs e)
{
}
private void bindingSource1_CurrentChanged(object sender, EventArgs e)
{
}
}
}
SQL query tool

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace database_v3
{
public partial class frmSQLTester : Form
{
public frmSQLTester()
{
InitializeComponent();
}
SqlConnection booksConnection;
private void frmSQLTester_Load(object sender, EventArgs e)
{
booksConnection = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=DataDirectory\\sakerDB.mdf;Integrated Security=True;User Instance=True");
}
private void frmSQLTester_FormClosing(object sender, FormClosingEventArgs e)
{
booksConnection.Close();
booksConnection.Dispose();
}
private void btnTest_Click(object sender, EventArgs e)
{
SqlCommand resultsCommand = null;
SqlDataAdapter resultsAdapter = new SqlDataAdapter();
DataTable resultsTable = new DataTable();
try
{
// establish command object and data adapter
resultsCommand = new SqlCommand(txtSQLTester.Text, booksConnection);
resultsAdapter.SelectCommand = resultsCommand;
resultsAdapter.Fill(resultsTable);
// bind grid view to data table
grdSQLTester.DataSource = resultsTable;
lblRecords.Text = resultsTable.Rows.Count.ToString();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error in Processing SQL", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
resultsCommand.Dispose();
resultsAdapter.Dispose();
resultsTable.Dispose();
}
}
}

lørdag 16. mai 2009

MySQL

Prompt Meaning
mysql> Ready for new command.
-> Waiting for next line of multiple-line command.
'> Waiting for next line, waiting for completion of a string that began with a single quote (“'”).
"> Waiting for next line, waiting for completion of a string that began with a double quote (“"”). `> Waiting for next line, waiting for completion of an identifier that began with a backtick (“`”).
/*> Waiting for next line, waiting for completion of a comment that began with /*.
________________________________________________
________________________________________________


mysql> SELECT VERSION(), CURRENT_DA

+------------------+--------------+
VERSION() CURRENT_DATE
+------------------+--------------+
5.1.34-community 2009-05-16
+------------------+--------------+
1 row in set (0.00 sec)
________________________________________________
________________________________________________

mysql> SELECT SIN(PI()/4), (4+1)*5;
+------------------+---------+
SIN(PI()/4) (4+1)*5
+------------------+---------+
0.70710678118655 25
+------------------+---------+
1 row in set (0.02 sec
________________________________________________
________________________________________________

mysql> SELECT VERSION(); SELECT NOW();
+-----------------+
VERSION()
+-----------------+
5.1.34-community
+-----------------+
1 row in set (0.00 sec)
+---------------------+
NOW()
+---------------------+
2009-05-16 11:17:49
+---------------------+
1 row in set (0.00 sec)
________________________________________________
________________________________________________
mysql> SELECT
-> USER()
-> ,
-> CURRENT_DATE;
+---------------+--------------+
USER() CURRENT_DATE
+---------------+--------------+
root@localhost 2009-05-16
+---------------+--------------+
________________________________________________
________________________________________________

mysql> SELECT * FROM my_table WHERE name = 'Smith AND age <>
'> `c
'> \c
'> '\c
mysql>
________________________________________________
mysql> SHOW DATABASES;
+----------+
Database
+----------+
mysql
test
tmp
+----------+

________________________________________________
________________________________________________

mysql> CREATE DATABASE menagerie;

mysql> CREATE TABLE pet (name VARCHAR(20), owner VARCHAR(20),
-> species VARCHAR(20), sex CHAR(1), birth DATE, death DATE);

mysql> SHOW TABLES;
+---------------------+
Tables in menagerie
+---------------------+
pet
+---------------------+

mysql> DESCRIBE pet;
+---------+-------------+------+-----+---------+-------+
Field Type Null Key Default Extra
+---------+-------------+------+-----+---------+-------+
name varchar(20) YES NULL
owner varchar(20) YES NULL
species varchar(20) YES NULL
sex char(1) YES NULL
birth date YES NULL
death date YES NULL
+---------+-------------+------+-----+---------+-------+

________________________________________________
________________________________________________

in text file use /N for NULL an TAB to space between values

name owner species sex birth death

Fluffy Harold cat f 1993-02-04 \N

Claws Gwen cat m 1994-03-17 \N

Buffy Harold dog f 1989-05-13 \N

Fang Benny dog m 1990-08-27 \N

Bowser Diane dog m 1979-08-31 1995-07-29

Chirpy Gwen bird f 1998-09-11 \N

Whistler Gwen bird \N 1997-12-09 \N

Slim Benny snake m 1996-04-29 \N

save to c:\temp\pet.txt

mysql> LOAD DATA LOCAL INFILE 'c:/temp/pet.txt' INTO TABLE pet;
Query OK, 9 rows affected, 10 warnings (0.02 sec)Records: 9
Deleted: 0 Skipped: 0 Warnings: 10

mysql> INSERT INTO pet -> VALUES ('Puffball','Diane','hamster','f','1999-03-30',NULL);
Query OK, 1 row affected (0.01 sec)

________________________________________________
________________________________________________

Retrieving Information from a Table


The SELECT statement is used to pull information from a table. The general form of the statement is:

SELECT what_to_select
FROM which_table
WHERE conditions_to_satisfy;

what_to_select indicates what you want to see. This can be a list of columns, or * to indicate “all columns.”

which_table indicates the table from which you want to retrieve data.

The WHERE clause is optional. If it is present, conditions_to_satisfy specifies one or more conditions that rows must satisfy to qualify for retrieval.

________________________________________________
________________________________________________

mysql> SELECT * FROM pet;
+----------+--------+---------+------+------------+------------+
name owner species sex birth death
+----------+--------+---------+------+------------+------------+
Fluffy Harold cat f 1993-02-04 NULL
Claws Gwen cat m 1994-03-17 NULL
Buffy Harold dog f 1989-05-13 NULL
Fang Benny dog m 1990-08-27 NULL
Bowser Diane dog m 1979-08-31 1995-07-29
Chirpy Gwen bird f 1998-09-11 NULL
Whistler Gwen bird NULL 1997-12-09 NULL
Slim Benny snake m 1996-04-29 NULL
Puffball Diane hamster f 1999-03-30 NULL
+----------+--------+---------+------+------------+------------+

________________________________________________
________________________________________________

Delete info i table

mysql> DELETE FROM pet;
________________________________________________
________________________________________________

change value in Birth to 1989-08-31

mysql> UPDATE pet SET birth = '1989-08-31' WHERE name = 'Bowser';
________________________________________________
________________________________________________

mysql> SELECT * FROM pet WHERE name = 'Bowser';
+--------+-------+---------+------+------------+------------+
name owner species sex birth death
+--------+-------+---------+------+------------+------------+
Bowser Diane dog m 1989-08-31 1995-07-29
+--------+-------+---------+------+------------+------------+
________________________________________________
________________________________________________

mysql> SELECT * FROM pet WHERE birth >= '1998-1-1';
+----------+-------+---------+------+------------+-------+
name owner species sex birth death
+----------+-------+---------+------+------------+-------+
Chirpy Gwen bird f 1998-09-11 NULL
Puffball Diane hamster f 1999-03-30 NULL
+----------+-------+---------+------+------------+-------________________________________________________
________________________________________________

mysql> SELECT * FROM pet WHERE species = 'dog' AND sex = 'f';
+-------+--------+---------+------+------------+-------+
name owner species sex birth death
+-------+--------+---------+------+------------+-------+
Buffy Harold dog f 1989-05-13 NULL
+-------+--------+---------+------+------------+-------+

________________________________________________
________________________________________________

mysql> SELECT * FROM pet WHERE species = 'snake' OR species = 'bird';
+----------+-------+---------+------+------------+-------+
name owner species sex birth death
+----------+-------+---------+------+------------+-------+
Chirpy Gwen bird f 1998-09-11 NULL
Whistler Gwen bird NULL 1997-12-09 NULL
Slim Benny snake m 1996-04-29 NULL
+----------+-------+---------+------+------------+-------+

________________________________________________
________________________________________________

mysql> SELECT * FROM pet WHERE (species = 'cat' AND sex = 'm')
-> OR (species = 'dog' AND sex = 'f');
+-------+--------+---------+------+------------+-------+
name owner species sex birth death
+-------+--------+---------+------+------------+-------+
Claws Gwen cat m 1994-03-17 NULL
Buffy Harold dog f 1989-05-13 NULL
+-------+--------+---------+------+------------+-------+

________________________________________________
________________________________________________

mysql> SELECT owner FROM pet;
+--------+
owner
+--------+
Harold
Gwen
Harold
Benny
Diane
Gwen
Gwen
Benny
Diane
+--------+

mysql> SELECT DISTINCT owner FROM pet;
+--------+
owner
+--------+
Benny
Diane
Gwen
Harold
+--------+

________________________________________________

mysql> SELECT name, species, birth FROM pet
-> WHERE species = 'dog' OR species = 'cat';
+--------+---------+------------+
name species birth
+--------+---------+------------+
Fluffy cat 1993-02-04
Claws cat 1994-03-17
Buffy dog 1989-05-13
Fang dog 1990-08-27
Bowser dog 1989-08-31
+--------+---------+------------+

________________________________________________

mysql> SELECT name, birth FROM pet ORDER BY birth;
+----------+------------+
name birth
+----------+------------+
Buffy 1989-05-13
Bowser 1989-08-31
Fang 1990-08-27
Fluffy 1993-02-04
Claws 1994-03-17
Slim 1996-04-29
Whistler 1997-12-09
Chirpy 1998-09-11
Puffball 1999-03-30
+----------+------------+

________________________________________________
________________________________________________

mysql> SELECT name, birth FROM pet ORDER BY birth DESC;
+----------+------------+
name birth
+----------+------------+
Puffball 1999-03-30
Chirpy 1998-09-11
Whistler 1997-12-09
Slim 1996-04-29
Claws 1994-03-17
Fluffy 1993-02-04
Fang 1990-08-27
Bowser 1989-08-31
Buffy 1989-05-13
+----------+------------+

________________________________________________
________________________________________________

mysql> SELECT name, species, birth FROM pet
-> ORDER BY species, birth DESC;
+----------+---------+------------+
name species birth
+----------+---------+------------+
Chirpy bird 1998-09-11
Whistler bird 1997-12-09
Claws cat 1994-03-17
Fluffy cat 1993-02-04
Fang dog 1990-08-27
Bowser dog 1989-08-31
Buffy dog 1989-05-13
Puffball hamster 1999-03-30
Slim snake 1996-04-29
+----------+---------+------------+

________________________________________________
________________________________________________

mysql> SELECT name, birth, CURDATE(),
-> (YEAR(CURDATE())-YEAR(birth))
-> - (RIGHT(CURDATE(),5) AS age
-> FROM pet;

+----------+------------+------------+------+
name birth CURDATE() age
+----------+------------+------------+------+
Fluffy 1993-02-04 2003-08-19 10
Claws 1994-03-17 2003-08-19 9
Buffy 1989-05-13 2003-08-19 14
Fang 1990-08-27 2003-08-19 12
Bowser 1989-08-31 2003-08-19 13
Chirpy 1998-09-11 2003-08-19 4
Whistler 1997-12-09 2003-08-19 5
Slim 1996-04-29 2003-08-19 7
Puffball 1999-03-30 2003-08-19 4
+----------+------------+------------+------+

mysql> SELECT name, birth, CURDATE(),
-> (YEAR(CURDATE())-YEAR(birth))
-> - (RIGHT(CURDATE(),5) AS age
-> FROM pet ORDER BY age;
+----------+------------+------------+------+
name birth CURDATE() age
+----------+------------+------------+------+
Chirpy 1998-09-11 2003-08-19 4
Puffball 1999-03-30 2003-08-19 4
Whistler 1997-12-09 2003-08-19 5
Slim 1996-04-29 2003-08-19 7
Claws 1994-03-17 2003-08-19 9
Fluffy 1993-02-04 2003-08-19 10
Fang 1990-08-27 2003-08-19 12
Bowser 1989-08-31 2003-08-19 13
Buffy 1989-05-13 2003-08-19 14
+----------+------------+------------+------+

mysql> SELECT name, birth, CURDATE(),
-> (YEAR(CURDATE())-YEAR(birth))
-> - (RIGHT(CURDATE(),5) AS age
-> FROM pet ORDER BY name;

+----------+------------+------------+------+
name birth CURDATE() age
+----------+------------+------------+------+
Bowser 1989-08-31 2003-08-19 13
Buffy 1989-05-13 2003-08-19 14
Chirpy 1998-09-11 2003-08-19 4
Claws 1994-03-17 2003-08-19 9
Fang 1990-08-27 2003-08-19 12
Fluffy 1993-02-04 2003-08-19 10
Puffball 1999-03-30 2003-08-19 4
Slim 1996-04-29 2003-08-19 7
Whistler 1997-12-09 2003-08-19 5
+----------+------------+------------+------+


________________________________________________
________________________________________________

mysql> SELECT name, birth, death,
-> (YEAR(death)-YEAR(birth)) - (RIGHT(death,5) AS age
-> FROM pet WHERE death IS NOT NULL ORDER BY age;
+--------+------------+------------+------+
name birth death age
+--------+------------+------------+------+
Bowser 1989-08-31 1995-07-29 5
+--------+------------+------------+------+

________________________________________________
________________________________________________

MySQL provides several functions for extracting parts of dates, such as YEAR(), MONTH(), and DAYOFMONTH(). MONTH() is the appropriate function here.

mysql> SELECT name, birth, MONTH(birth) FROM pet;
+----------+------------+--------------+
name birth MONTH(birth)
+----------+------------+--------------+
Fluffy 1993-02-04 2
Claws 1994-03-17 3
Buffy 1989-05-13 5
Fang 1990-08-27 8
Bowser 1989-08-31 8
Chirpy 1998-09-11 9
Whistler 1997-12-09 12
Slim 1996-04-29 4
Puffball 1999-03-30 3
+----------+------------+--------------+

________________________________________________
________________________________________________

mysql> SELECT * FROM pet WHERE name LIKE 'b%';
+--------+--------+---------+------+------------+------------+
name owner species sex birth death
+--------+--------+---------+------+------------+------------+
Buffy Harold dog f 1989-05-13 NULL
Bowser Diane dog m 1989-08-31 1995-07-29
+--------+--------+---------+------+------------+------------+

mysql> SELECT * FROM pet WHERE name LIKE '%fy';
+--------+--------+---------+------+------------+-------+
name owner species sex birth death
+--------+--------+---------+------+------------+-------+
Fluffy Harold cat f 1993-02-04 NULL
Buffy Harold dog f 1989-05-13 NULL
+--------+--------+---------+------+------------+-------+

mysql> SELECT * FROM pet WHERE name LIKE '%w%';
+----------+-------+---------+------+------------+------------+
name owner species sex birth death
+----------+-------+---------+------+------------+------------+
Claws Gwen cat m 1994-03-17 NULL
Bowser Diane dog m 1989-08-31 1995-07-29
Whistler Gwen bird NULL 1997-12-09 NULL
+----------+-------+---------+------+------------+------------+

To find names containing exactly five characters, use five instances of the “_” pattern character: mysql> SELECT * FROM pet WHERE name LIKE '_____';
+-------+--------+---------+------+------------+-------+
name owner species sex birth death
+-------+--------+---------+------+------------+-------+
Claws Gwen cat m 1994-03-17 NULL
Buffy Harold dog f 1989-05-13 NULL
+-------+--------+---------+------+------------+-------+

To find names beginning with “b”, use “^” to match the beginning of the name:

mysql> SELECT * FROM pet WHERE name REGEXP '^b';

To find names ending with “fy”, use “$” to match the end of the name:

mysql> SELECT * FROM pet WHERE name REGEXP 'fy$';

To find names containing exactly five characters, use “^” and “$” to match the beginning and end of the name, and five instances of “.” in between:

mysql> SELECT * FROM pet WHERE name REGEXP '^.....$';

________________________________________________
________________________________________________

mysql> SELECT COUNT(*) FROM pet;
+----------+
COUNT(*)
+----------+
9
+----------+


mysql> SELECT owner, COUNT(*) FROM pet GROUP BY owner;
+--------+----------+
owner COUNT(*)
+--------+----------+
Benny 2
Diane 2
Gwen 3
Harold 2
+--------+----------+

mysql> SELECT species, COUNT(*) FROM pet GROUP BY species;
+---------+----------+
species COUNT(*)
+---------+----------+
bird 2
cat 2
dog 3
hamster 1
snake 1
+---------+----------+

mysql> SELECT sex, COUNT(*) FROM pet GROUP BY sex;
+------+----------+
sex COUNT(*)
+------+----------+
NULL 1
f 4
m 4

mysql> SELECT species, sex, COUNT(*) FROM pet GROUP BY species, sex;
+---------+------+----------+
species sex COUNT(*)
+---------+------+----------+
bird NULL 1
bird f 1
cat f 1
cat m 1
dog f 1
dog m 2
hamster f 1
snake m 1
+---------+------+----------+

________________________________________________
________________________________________________

________________________________________________
________________________________________________

________________________________________________
________________________________________________

fredag 15. mai 2009

input to database

private void button3_Click(object sender, EventArgs e)
{
string connection = "Data Source=.\\SQLEXPRESS; AttachDbFilename=\\\\xxx\\felles\\xxx\\Drift\\NOC\\xxx\\sakerDB.mdf; Integrated Security=True; Connect Timeout=30; User Instance=True; Asynchronous Processing=true";
//sakerConnection = new SqlConnection("Data Source=.\\SQLEXPRESS; AttachDbFilename=C:\\Documents and Settings\\glennj\\Mine dokumenter\\Visual Studio 2008\\Projects\\database_v3\\database_v3\\sakerDB.mdf; Integrated Security=True; Connect Timeout=30; User Instance=True; ");

SqlConnection newCon = new SqlConnection(connection);

newCon.Open();

SqlCommand insertCommand = new SqlCommand("INSERT INTO glennj(Dato, Nye_T, Allerede_T) VALUES ('" + dateTimePicker1.Value + "')('"+textBox1.Text+"')('"+ textBox2.Text + "')", newCon);

insertCommand.BeginExecuteNonQuery();
}

mandag 11. mai 2009

text num edit

private void textBox1_TextChanged(object sender, EventArgs e)
{
textBox1.KeyPress += new KeyPressEventHandler(Form1_KeyPress);

decimal sum = decimal.Parse(textBox1.Text) + decimal.Parse(textBox2.Text);
label1.Text = sum.ToString();
}

private void Form1_KeyPress(object sender, KeyPressEventArgs e)
{
if (((e.KeyChar < '0') || (e.KeyChar > '9')) && (e.KeyChar!=(char)Keys.Back))
e.Handled = true;
}

only allow text in textbox

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;
using System.Text.RegularExpressions;

namespace numbox_test
{


public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
Regex FormatControl = new Regex(@"\D");
private void textBox1_TextChanged(object sender, EventArgs e)
{
if (FormatControl.IsMatch(textBox1.Text))
{
textBox1.Text = "";
MessageBox.Show("Only numeric format would be accepted");
}

}

søndag 10. mai 2009

database

private void dataF1_Load(object sender, EventArgs e)
{
label1.Text = DateTime.Now.ToString("d");
glennjTableAdapter1.Fill(this.database1DataSet11.glennj);
henryaTableAdapter1.Fill(this.database1DataSet11.henrya);
}
private void button1_Click(object sender, EventArgs e)
{
bindingSource1.EndEdit();
glennjTableAdapter1.Update(database1DataSet11.glennj.Rows.Add(label1.Text, textBox1.Text, textBox2.Text));
henryaTableAdapter1.Update(database1DataSet11.henrya.Rows.Add(label1.Text, textBox3.Text, textBox4.Text));
}
//setter ny dato p† label//
private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
{
label1.Text = dateTimePicker1.Value.ToString("d");
}

onsdag 6. mai 2009

radiobutton code

private void rdo_CheckedChanged(object sender, System.EventArgs e)
{
RadioButton rdo = sender as RadioButton;
if (rdo.Checked)
{
switch (rdo.Text)
{
case "Bottom":
this.Edge = AppBarEdges.Bottom;
break;
case "Top":
this.Edge = AppBarEdges.Top;
break;
case "Left":
this.Edge = AppBarEdges.Left;
break;
case "Right":
this.Edge = AppBarEdges.Right;
break;
case "Float":
this.Edge = AppBarEdges.Float;
break;
}
}
}

fredag 1. mai 2009

Auto drawing text from text file.

<------------------------------------------------------------------>
first i made the software, but it kept drawing ontop of it self all teh time, so a added clear.

graphicsObj.Clear(Color.Aqua);

and its workig just fine :):):)
<------------------------------------------------------------------>


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 test_drawing
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//text variablelen
public string teXt;
public void Form1_Load(object sender, EventArgs e)
{
}
//tegne ned texten
public void Form1_Paint(object sender, PaintEventArgs e)
{
}
//timed ticker updater
private void timer1_Tick(object sender, EventArgs e)
{
string file_name = "c:\\temp\\test.txt";
{
System.IO.StreamReader objReader;
objReader = new System.IO.StreamReader(file_name);
//textBox1.Text = objReader.ReadToEnd();
teXt = objReader.ReadToEnd();
objReader.Close();
}
System.Drawing.Graphics graphicsObj;
graphicsObj = this.CreateGraphics();
graphicsObj.Clear(Color.Aqua);
Font myFont = new System.Drawing.Font("Helvetica", 40, FontStyle.Italic);
Brush myBrush = new SolidBrush(System.Drawing.Color.Red);
graphicsObj.DrawString(teXt, myFont, myBrush, 30, 30);
}
}
}