I am new to working with databases. I made a simple form app to display this data table however, I can't get the data into the database so that the form displays it. I initially had only 1 employee listed here and he shows up in my application. I just added the last 3 employees into this table view but if I run the app, only the original employee (id 1) shows up. How do I commit the last 3 employees' info into the database? I Googled some info on this and found a select * from dbo.EmployeeInfo query and ran it, it displays the employee info right but it doesn't seem to change the database with the new info. Thank you.
I was stuck here too.
What I did was -
1) Updated the values and after updating the last values, I pressed Enter
It seems to work for me.
Enter button on keyboard makes life simple. :)
I created a form with a GridView, and binded it with a Datasource it shows me the data in the form u showed above...
Added some textboxes for input......
The code below shows how it binds the datasource with the gridview and how you would insert data permanently using input from textboxes at a button click event
private void Form1_Load(object sender, EventArgs e)
{
// using a gridview by binding the dataset with it at form load
//It creates the table for you with the relevant columns
//and fills it with this line of code
this.employeesTableAdapter.Fill(this.practiceDBDataSet.Employees);
}
private void btnSubmit_Click(object sender, EventArgs e)
{
//on add user button click
//I access the tableadpater created by the dataset to be accessed by the gridview
//the txt.... represents my fields names according to the database
employeesTableAdapter.Insert(txtName.Text, txtSurname.Text, txtAge.Text, Convert.ToInt32(txtAge.Text));
}
And then the txt.... are in place for the data required by the Database, where you would be getting your input from.........
Related
I am able to make particular column data bold but Unable to set datagridview column data to bold after data loaded in datagridview.
I am using below code to make it Bold which is working if I Set this in columnAdd event but unable to change after data loaded in to the datagridview.
dataGridView1.Columns[1].DefaultCellStyle.Font = new System.Drawing.Font("Roboto", 8.5F, FontStyle.Bold);
please help if its possible.. I am using windows form DataGridView
2017Button || 2010Button || 2005Button
On clicking particular button I need to highlight that particular column. For Example, My data contains 3 Columns 2017 Data, 2010 Data, 2005 Data, Which Year I Select from above button out of 2017,2010,2005 button, that column should get bold.. And also I don't want to rebind the data to gridview
You must try it on below event
void dataGridView1_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
{
dataGridView1.Columns[1].DefaultCellStyle.Font = new System.Drawing.Font("Roboto", 8.5F, FontStyle.Bold);
}
I have a DataGridView in C# which is connected with my Access database. I see all the books on my DataGridView. I have created a mouse Click event handler to select a row than I can save that row, as you see below:
private void Mouse_Click(object sender, MouseEventArgs e)
{
try
{
temp = dataGridView1.SelectedRows[0].Index.ToSt…
//This one is selecting the row. To do that select panel>event> on MouseClick write name and double click:
MessageBox.Show("You have selected the row " + temp);
}
catch
{
}
}
It works when I open the form. However, after I save the selected row to another database, the Mouse Click event handler stop working. In other words, after saving the first selected row, when I come back to select another row and save to database the Mouse Click Event handler does not work. The Message says row is out of range.
You didn't give too much information related to connection type, Event Handler and more importantly the way you save/update the record so I'm just guessing here: aren't you accidentally overwriting the DataSource of your grid? That's the only thing I can imagine for such behavior ("row is out of range" - which also assumes the event still works as intended but the code in the function cannot see the data anymore).
This is a pretty small program, so I just used the autogenerated code for my datasource and dragged/dropped a datagridview on my WinForm. I'm trying to manually update a column in a row, but it fails each time I get to the "UpdateAll" of my tablemanager. Here's my code for double click of cell content:
private void dgv1DataGridView_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
{
try
{
string delMemberID = dgv1DataGridView.Rows[e.RowIndex].Cells[0].Value.ToString();
ds1DataSet.Table1.Rows[ds1DataSet.Table1.Rows.IndexOf(ds1DataSet.Table1.FindByMemberID(delMemberID))][9] = MemberID.ToString();
this.Validate();
this.bs1BindingSource.EndEdit();
this.tableAdapterManager.UpdateAll(this.ds1DataSet);
MessageBox.Show("Replacement Successful");
this.Close();
}
catch
{
MessageBox.Show("Replacement Failed");
}
}
My expectations are; when a user double clicks anywhere inside a row of the datagridview, it will update that row with a different "MemberID" for that column, save the data everywhere (including database), and then close the form (to return the parent form).
For some reason, my tableAdapterManager wasn't linked to my TableAdapter on that form - once I linked them, the above code worked fine.
To be more precise, I clicked on the design view of my form and clicked the the tableAdapterManager at the bottom of the design window. Then looking in the "Properties" window, I noticed that the TableAdapter was blank (if you used a wizard to create the DataSource, then it will be named the same as the table in your DataSource). Once I selected the correct name for the TableAdapter, everything worked perfect.
I have a populated Datagridview, which gets its data from a DataTableAdapter.
I have a separate button on my form. When I click the button I want the DataTable to refresh and repopulate completely.
Seems so easy, but I can't find a way to do this.
Thanks in advance
If you wish to swap the code for dynamic grid functionality, right click on your datatable and add a new query (green box in the SS):
Select * from tablename
Then go locate the line in the form_load that takes care of the data population:
this.yourTableAdapter.Fill(this.yourDataSet.yourdatatable);
The default SQL query is always called .Fill, but in case you add a new query the second one will be called (orange box in SS):
this.yourTableAdapter.FillBy(this.yourDataSet.yourdatatable);
By running this second method somewhere in your code (a button press maybe) the grid should change to the new sql command and display the new results in the gridview:
protected void Button1_Click(object sender, EventArgs e)
{
this.yourTableAdapter.FillBy(this.yourDataSet.yourdatatable);
}
I'm trying to create a simple table navigation screen in WPF using the entity framework on a database with one table, Students. The screen basically has the the students name and surname and back and forwards button.
The datacontext is pointing directly to the Students table and is setup as follows:
private DBEntities _entity = new DBEntities();
this.Datacontext = _entity.Students;
This works and I see the first entry on the table on the screen.
My problem is I can't see any way to navigate to the next entry when I click the next button.
There is First() method on Students but no Next().
All the solutions I've found via google dump the entire table in a List and navigate the list.
I'm wondering if there isn't a simpler way that I'm missing?
msdn topic here...
First get the collection as an ICollectionView,
ICollectionView view1 = CollectionViewSource.GetDefaultView(_entity.Students);
Now you can navigate the collection, in this case you can use MoveCurrentToNext