------------------------------------------------------------------------------------------------------------------
Moin leute,
ich bin derzeit dabei Programmieren zu lernen und bin noch ziemlich weit am anfang. Jedenfalls habe ich eine listbox, welche von einem radio sender die song namen von der webseite abgreift. Der titel wird in der listbox angezeigt und alle 60sekunden aktuallisiert ob ein neuer titel drinnen steht.
Jetzt will ich, dass die titel abgespeichert werden, sobald man auf einem button klickt.
Code:
private void button1_Click_1(object sender, EventArgs e)
{
if (listModerator.SelectedIndex == 0)
{
SqlConnection TBTracks = new SqlConnection();
SqlCommand cmd = new SqlCommand();
TBTracks.ConnectionString = @"Data Source=.\SQLEXPRESS";
//TBTracks.ConnectionString =
// ".\SQLEXPRESS"+
// "Data Source=MeinPC\SQLEXPRESS";
cmd.Connection = TBTracks;
con = new SqlConnection(@"Data Source=MeinPC\SQLEXPRESS;Initial Catalog=PVP;Integrated Security=True");
con.Open();
cmd = new SqlCommand("SELECT * FROM TB_TRACKS");
cmd.Connection = con;
da = new SqlDataAdapter(cmd);
da.Fill(dt);
listModerator.Text = dt.Rows[0]["Arstist"].ToString();
cmd.CommandText =
"insert into TB_TRACKS " +
"(title, artist)" +
listModerator.Text;
MessageBox.Show(cmd.CommandText);
con.Close();
Spaltenname: Datentyp: NULL-Wert:
id uniqueidentifier nein
title nvarchar(50) ja
artist nvarchar(50) ja
Das sind so einige sachen, welche ich alle versucht habe um überhaupt irgendwas zu machen (alles mögliche schon wieder gelöscht und davon sollte eigentlich die hälfte auskommentiert sein).
Ich beschäftige mich seit heute leider erst zum ersten mal überhaupt mit datenbanken, weshalb ich keine ahnung habe wie ich vor gehen soll.
Ich nutze den Microsoft SQL Server b.z.w den SQL Server Managment Sudio.
Ich würde mich freuen, wenn mir jemand helfen kann und dabei ein wenig erklären könnte .
Danke schonmal im vorraus
English:
-----------------------------------------------------------
Hey guys,
i learning programming but i´m programming only since 2 Week´s.
I want to connect to my SQL Database and save the Song titel from a Radio.
The song namens are in the listbox and there updating ervery minute.
My code is very false and have many trash, but i hope you know, what i want ^^
Code:
private void button1_Click_1(object sender, EventArgs e)
{
if (listModerator.SelectedIndex == 0)
{
SqlConnection TBTracks = new SqlConnection();
SqlCommand cmd = new SqlCommand();
TBTracks.ConnectionString = @"Data Source=.\SQLEXPRESS";
//TBTracks.ConnectionString =
// ".\SQLEXPRESS"+
// "Data Source=MeinPC\SQLEXPRESS";
cmd.Connection = TBTracks;
con = new SqlConnection(@"Data Source=MeinPC\SQLEXPRESS;Initial Catalog=PVP;Integrated Security=True");
con.Open();
cmd = new SqlCommand("SELECT * FROM TB_TRACKS");
cmd.Connection = con;
da = new SqlDataAdapter(cmd);
da.Fill(dt);
listModerator.Text = dt.Rows[0]["Arstist"].ToString();
cmd.CommandText =
"insert into TB_TRACKS " +
"(title, artist)" +
listModerator.Text;
MessageBox.Show(cmd.CommandText);
con.Close();
The table have 3 column und his name is TB_Tracks.
Clumnname: Datatype: nil value:
id uniqueidentifier false
title nvarchar(50) true
artist nvarchar(50) true
Sorry for my very bad english, but i can only talk in english ^^
Thanks
Also das Lesen der Datenbank funktioniert aktuell. Bloß das Schreiben noch nicht, wobei mir so langsam die ideen ausgehen^^
Mein aktueller Code:
Code:
private void button1_Click_1(object sender, EventArgs e)
{
if (listModerator.SelectedIndex == 0)
{
listModerator.ToString = Trackname();
SqlConnection TBTracks = new SqlConnection();
SqlCommand TBCmd = new SqlCommand();
SqlDataAdapter writer;
TBTracks.ConnectionString = @"Data Source=EDP0026NB\SQLEXPRESS;Initial Catalog=PVP;Integrated Security=True";
TBCmd.CommandText = "INSERT INTO TB_TRACKS (title) VALUES ('" + listModerator + "');";
TBCmd.CommandType = CommandType.Text;
TBCmd.Connection = TBTracks;
TBCmd.Parameters.AddWithValue("@title", listModerator.Text);
//TBCmd.Parameters.AddWithValue("@artist", txtArtist.Text);
TBTracks.Open();
//TBCmd.ExecuteNonQuery();
TBTracks.Close();
}
}
private void cmdTracksshow_Click(object sender, EventArgs e)
{
if (listModerator.SelectedIndex == 0)
{
SqlConnection TBTracks = new SqlConnection();
SqlCommand TBCmd = new SqlCommand();
SqlDataReader reader;
TBTracks.ConnectionString = @"Data Source=EDP0026NB\SQLEXPRESS;Initial Catalog=PVP;Integrated Security=True";
TBCmd.Connection = TBTracks;
TBCmd.CommandText = "SELECT title from TB_TRACKS";
try
{
TBTracks.Open();
reader = TBCmd.ExecuteReader();
lstTracks.Items.Clear();
while (reader.Read())
{
lstTracks.Items.Add(
reader["title"]);
}
reader.Close();
TBTracks.Close();
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}






" verwendet. Es werden GUID's erstellt, welche 36 Stellen haben. Für deine Anwendung ist dies unnötig, hier reicht als Datentyp "int", anschließend die Spalte auf "Primärschlüssel" und "Autoinkrement" stellen. 