kurde chyba umre z tym c# :)
ok dodałem już referencje, juz wiem o co chodzi :)
błędów żadnych nie mam już ale podczas dodawania do bazy wartosci z texboxa wyskakuje mi blad w linijce:
using (SqlConnection scon =new SqlConnection(ConfigurationManager.ConnectionStrings["cupit"].ConnectionString))
zmieniłem już tam nazwy aby do siebie pasowały.
wkleje raz jeszcze cały kod:
Form1
using System;
using System.Data.SqlClient;
using System.Configuration;
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.IO;
namespace cupit
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'uzytkownicyDataSet.uzytkownicy' table. You can move, or remove it, as needed.
this.uzytkownicyTableAdapter.Fill(this.uzytkownicyDataSet.uzytkownicy);
}
private void b_id_Click(object sender, EventArgs e)
{
string query = "INSERT INTO uzytkownicy (id_id) VALUES (@a)";
SqlCommand dodaj = new SqlCommand(query);
dodaj.Parameters.Add(new SqlParameter("a",t_id.Text ));
dodaj.CommandType = CommandType.Text;
using (SqlConnection scon =new SqlConnection(ConfigurationManager.ConnectionStrings["cupit"].ConnectionString))
{
dodaj.Connection = scon;
scon.Open();
dodaj.ExecuteNonQuery();
}
}
}
}
app.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
</configSections>
<connectionStrings>
<add name="cupit.Properties.Settings.uzytkownicyConnectionString"
connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\uzytkownicy.mdf;Integrated Security=True;User Instance=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
mój app.config tak wygląda, bo póki co to jest prawie pusty program... chyba, że o coś innego Ci chodziło.. ?
błąd, który się pojawia przy próbie dodawania np: 1 do bazy, w momencie wciśnięcia buttona to:
System.NullReferenceException was unhandled
Message="Odwołanie do obiektu nie zostało ustawione na wystąpienie obiektu."
Source="cupit"
StackTrace:
w cupit.Form1.b_id_Click(Object sender, EventArgs e) w C:\Users\Maciej\Desktop\cupit\cupit\Form1.cs:wiersz 44
w System.Windows.Forms.Control.OnClick(EventArgs e)
w System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
w System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
w System.Windows.Forms.Control.WndProc(Message& m)
w System.Windows.Forms.ButtonBase.WndProc(Message& m)
w System.Windows.Forms.Button.WndProc(Message& m)
w System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
w System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
w System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
w System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
w System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
w System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
w cupit.Program.Main() w C:\Users\Maciej\Desktop\cupit\cupit\Program.cs:wiersz 18
w System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
w Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
w System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
w System.Threading.ThreadHelper.ThreadStart()
InnerException: