Ask a questionAsk a question
 

Questionconnectionstring property has not been initialized windows forms

  • Wednesday, October 21, 2009 11:59 AMMassie92 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hello

    if been searching the web for a solution but noting worked. I make a connectionstring to my sql database. But when i wan't to store the typed data by pushing a button in wouldn't work. If you need more information ask. 

    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 GIPBeta
    {
        public partial class Form1 : Form
        {
            //Aanmaken van een string variable
            private string LK_Naam;

            public Form1()
            {
                InitializeComponent();
            }

            private void sqlDataAdapter1_RowUpdated(object sender, SqlRowUpdatedEventArgs e)
            {
                this.sqlDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
                new System.Data.Common.DataTableMapping("Table", "LeerkrachtenTB", new System.Data.Common.DataColumnMapping[] {
                            new System.Data.Common.DataColumnMapping("LK_ID", "LK_ID"),
                            new System.Data.Common.DataColumnMapping("LK_Naam", "LK_Naam")})});

            }
            private void Test()
            {
                sqlCommand1.CommandText = "INSERT INTO LeerkrachtenTB(LK_ID, LK_Naam) VALUES (@LK_ID, @LK_Naam); SELECT LK_ID" +
                   ", LK_Naam FROM LeerkrachtenTB";
                sqlCommand1.Connection = sqlConnection1;
                sqlCommand1.Parameters.AddRange(new System.Data.SqlClient.SqlParameter[] {
                new System.Data.SqlClient.SqlParameter("@LK_ID", System.Data.SqlDbType.Int, 4, "LK_ID"),
                new System.Data.SqlClient.SqlParameter("@LK_Naam", System.Data.SqlDbType.NVarChar, 50, "LK_Naam")});
                // 
                // sqlConnection1
                // 
                sqlConnection1.ConnectionString = "data source=localhost;initial catalog=GIPDatabase;persist security info=False;" +
                    "user id=GIPBeheerder; password=CMscout; workstation id=THOMAS-PC;packet size=8000";
                sqlConnection1.FireInfoMessageEventOnUserErrors = false;
                // 
                // sqlSelectCommand1
                // 
                sqlCommand2.CommandText = "SELECT LK_ID, LK_Naam FROM LeerkrachtenTB";
                sqlCommand2.Connection = sqlConnection1;
     
            }

            private void Form1_Load(object sender, EventArgs e)
            {

            }

            private void buttonSave_Click(object sender, EventArgs e)
            {
                if (textBoxNaam.Text == "")
                    MessageBox.Show("Please enter your name");
                else
                {
                    sqlConnection1.Open();

                    string insert = "INSERT INTO LeerkrachtenTB(LK_Naam) VALUES ('" + LK_Naam + "')";
                    SqlCommand cmd = new SqlCommand(insert, sqlConnection1);
                    cmd.ExecuteNonQuery();

                    sqlConnection1.Close();
                    MessageBox.Show("Je ben ingeschreven.");
                }

            }

            private void textBoxNaam_TextChanged(object sender, EventArgs e)
            {
                LK_Naam = textBoxNaam.Text.ToString();
            }




        }
    }

    • Moved byDaniel Roth Thursday, October 22, 2009 5:47 PMQuestion is related to Data Platform Development (From:ASMX Web Services and XML Serialization)
    •  

All Replies