I recently started learning C# and im stuck with a gridview and database.
I have a textbox and a button which will add the text in the textbox to my gridview.
but its not working as I want it to.
Problems:
the text from my textbox is not shown. when i click the button the 2nd time i get the following error “Cannot add an entity that allready exsists”.
if I click the array my self a new line is generated but it only shows numbers like, ” -1, -2, -3″ for each array..
if i try to change the numbers to text, the program fails big time.
This is what I have used;
gridview -linked it with my database
LINQ to SQL Classes
Service-based Database
this is my codes. trying to keep it simple as possible.
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 database_test2
{
public partial class Form1 : Form
{
Database1DataSet db = new Database1DataSet();
DataClasses1DataContext dblink = new DataClasses1DataContext();
Table1 tabel = new Table1();
public Form1()
{
InitializeComponent();
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
tabel.Materiale = Convert.ToString(textBox1.Text);
dblink.Table1s.InsertOnSubmit(tabel);
dblink.SubmitChanges();
}
private void database1DataSetBindingSource_CurrentChanged(object sender, EventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'database1DataSet.Table1' table. You can move, or remove it, as needed.
this.table1TableAdapter.Fill(this.database1DataSet.Table1);
}
}
}
The most common issue when startin asp.net webforms is forgetting calling
DataBind()method, after some changes, editing etc. This method inits data to view control in order to render it.