hi. I'm trying to make a simple c# program using sqlserver.
when i try to save something into database, it gives this error.
here's the code. that 15(age value) is the default value on my numericupdown
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 WindowsFormsApplication10
{
public partial class formDefineStudent : Form
{
public formDefineStudent()
{
InitializeComponent();
}
private void formDefineStudent_Load(object sender, EventArgs e)
{
txtStudentName.Text = "";
txtParentName.Text = "";
btnDelete2.Enabled = false;
}
private void btnSave2_Click(object sender, EventArgs e)
{
string cmdtext;
string connStr = "Data Source=FIRAT;Initial Catalog=school;Integrated Security=True";
SqlConnection conn = new SqlConnection(connStr);
conn.Open();
cmdtext = "insert into tblSTUDENT(FULLNAME, PARENTNAME, AGE) VALUES('"
+ txtStudentName.Text + "', '" + txtParentName.Text + "' " + txtAge.Text.ToString() +")";
SqlCommand cmd = new SqlCommand(cmdtext,conn);
cmd.ExecuteNonQuery();
conn.Close();
}
private void grdRefresh()
{
string connStr = " Initial Catalog = school ; Integrated Security =true";
SqlConnection conn = new SqlConnection(connStr);
conn.Open();
SqlDataAdapter dAdapter = new SqlDataAdapter("SELECT * FROM tblSTUDENT", conn);
DataTable dTable = new DataTable();
dAdapter.Fill(dTable);
dgStudentList.DataSource = dTable;
conn.Close();
}
}
}