I have created a database in microsoft office access. In form1.cs i added a DataGridView with the source from the database created. In tableDataSet.xsd/tabelAdapter i created a new query with 3 parameters which i use to insert the data in the database ( Name, Password, Age) . how can i use this query with that 3 parameters from 3 different textbox?
PS: i use only Windows Form Application, no asp.net or etc.
Code:
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 lucian
{
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 'jucatoriDataSet.jucator' table. You can move, or remove it, as needed.
this.jucatorTableAdapter.Fill(this.jucatoriDataSet.jucator);
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private void adaugareToolStripButton_Click(object sender, EventArgs e)
{
try
{
this.jucatorTableAdapter.Fill(this.jucatoriDataSet.jucator);
}
catch (System.Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}
}
private void button1_Click(object sender, EventArgs e)
{
}
}
}
Take a look at that article http://msdn.microsoft.com/en-us/magazine/cc163709.aspx
Basically you need to learn about ADO.NET :)
Related
This is my first assignment using C# and I've learned briefly about programming with Python in my pre-u. The C# form that I would like to show the user upon logging in can't be shown and instead, the program displays the Built errors msg, where I click on 'Yes' to continue running the last successful build. However, it will show one of the previous forms (which I have deleted from the program) instead - making it hard for me to test run and check for any other errors in my program.
The form I would like to show is TechnicianHome.
Error
There were built errors. Would you like to continue and run the last successful build?
Any help is much appreciated.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace ASSIGNMENT
{
public partial class TechnicianHome : Form
{
public static string name;
public TechnicianHome()
{
InitializeComponent();
}
public TechnicianHome (string n)
{
InitializeComponent();
name = n;
}
private void TechnicianHome_Load(object sender, EventArgs e)
{
lblWelcome.Text = "Welcome" + name;
}
private void button1_Click(object sender, EventArgs e)
{
ServiceRequests vr = new ServiceRequests();
this.Hide();
vr.ShowDialog();
}
private void button1_Click_1(object sender, EventArgs e)
{
UpdateProfile up = new UpdateProfile();
this.Hide();
up.ShowDialog();
}
}
}
i am new to .net i am having trouble playing videos automatically. I would be showing different textboxes here but i want the video to autplay without any buttons
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WMPLib;
namespace ThinkQDisplay
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void axWindowsMediaPlayer1_Enter(object sender, EventArgs e)
{
AxWindowsMediaPlayer1.URL = "C:\Users\Ramrod\Documents\Visual Studio 2012\Projects\ThinkQDisplay\ThinkQDisplay\sample.avi";
}
}
}
It keeps telling it is an unrecognized escape sequence. Also I would like to have a separate form (form2). Where I can choose what to play here on form 1. Is it also possible to have it looped?
private void axWindowsMediaPlayer1_Enter(object sender, EventArgs e)
{
axWindowsMediaPlayer1.URL = #"C:\Users\Ramrod\Documents\Visual Studio 2012\Projects\ThinkQDisplay\ThinkQDisplay\sampler.avi";
}
private void Form1_Load(object sender, EventArgs e)
{
axWindowsMediaPlayer1.settings.autoStart = true;
}
}
}
I am trying to "learn" C# and building my 1st database driven data entry application. I am coming from Oracle development, hence wondering whether am doing few things right, as most of the examples I could find are dealing with datasets derived using SQL
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace lSystem
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void l_PEOPLEBindingNavigatorSaveItem_Click(object sender, EventArgs e)
{
if ((string.IsNullOrWhiteSpace(fIRST_NAMETextBox.Text) || (string.IsNullOrWhiteSpace(cIVIL_IDTextBox.Text) ||
(string.IsNullOrWhiteSpace(tELEPHONE_NUMBERTextbox.Text)))))
{
MessageBox.Show("Error, one of the mandatory columns are not filled up");
return;
}
try
{
this.Validate();
this.pERSON_IDTextBox.Text = this.l_PEOPLETableAdapter.ScalarQuery().ToString();
this.l_PEOPLEBindingSource.EndEdit();
this.tableAdapterManager.UpdateAll(this.uNUDataSet);
}
catch (Exception ex)
{
MessageBox.Show("Exception happened, original message: " + ex.Message);
}
}
private void Form1_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'uNUDataSet.L_PEOPLE' table. You can move, or remove it, as needed.
this.l_PEOPLETableAdapter.Fill(this.uNUDataSet.L_PEOPLE);
// this.fIRST_NAMETextBox.Focus();
this.ActiveControl = this.fIRST_NAMETextBox;
}
private void sByName_Click(object sender, EventArgs e)
{
this.l_PEOPLETableAdapter.FillByNAME(this.uNUDataSet.L_PEOPLE, this.sByNameText.Text);
}
private void fIRST_NAMETextBox_Validated(object sender, EventArgs e)
{
if (string.IsNullOrWhiteSpace(fIRST_NAMETextBox.Text))
{
eNROLL_errorprovider.SetError(fIRST_NAMETextBox, "Name required");
fIRST_NAMETextBox.Focus();
}
}
private void cIVIL_IDTextBox_Validated(object sender, EventArgs e)
{
if (string.IsNullOrWhiteSpace(cIVIL_IDTextBox.Text))
{
eNROLL_errorprovider.SetError(cIVIL_IDTextBox, "Civil ID Number required");
cIVIL_IDTextBox.Focus();
}
}
private void tELEPHONE_NUMBERTextbox_Validated(object sender, EventArgs e)
{
if (string.IsNullOrWhiteSpace(tELEPHONE_NUMBERTextbox.Text))
{
eNROLL_errorprovider.SetError(tELEPHONE_NUMBERTextbox, "Telephone Number required");
tELEPHONE_NUMBERTextbox.Focus();
}
else
{
eNROLL_errorprovider.Clear();
}
}
}
}
What I am trying to do with the above piece of code is, unless the user enters first name, civil id number and supply the telephone number, the form shouldn't submit the data. For the person id, I am using a sequence, called through a scalar query attached to the table adaptor.
While I click the binding navigator save button, what should execute in order to fire the validation events attached with the text columns so that the error provider will get activated?
You need to register the event like the code below
public Form1()
{
InitializeComponent();
tELEPHONE_NUMBERTextbox.Validated += new EventHandler(tELEPHONE_NUMBERTextbox_Validated);
}
private void tELEPHONE_NUMBERTextbox_Validated(object sender, EventArgs e)
{
}
So, I've got a simple application that needs to view, insert, update, and delete data from an access db file by using the DataGrid tool in Visual Studio 2012. Upon initial load, my database loaded fine, and to my knowledge it is a bound data source:
I used an Access DB table called lawyers and created a binding data source called lawyerBindingSource attached to my lawyerGridView inside of my LawyerForm.
The problem is that when I relaunch my application, the newly inserted data does not refresh within my GridView. I've read similar stackoverflow questions on this topic, but have yet to find a solution. Please help! Here is my form code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace NewcomerAndAssociatesSystem
{
public partial class Lawyers : Form
{
public Lawyers()
{
InitializeComponent();
}
private void Lawyers_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'seniorProjectDb1DataSet.LawOffice' table. You can move, or remove it, as needed.
this.lawOfficeTableAdapter.Fill(this.seniorProjectDb1DataSet.LawOffice);
// TODO: This line of code loads data into the 'seniorProjectDb1DataSet.Lawyer' table. You can move, or remove it, as needed.
this.lawyerTableAdapter.Fill(this.seniorProjectDb1DataSet.Lawyer);
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private void lawyerReturnMain_Click(object sender, EventArgs e)
{
new MainForm().Show();
this.Hide();
}
private void dataGridView2_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private void fillByToolStripButton_Click(object sender, EventArgs e)
{
try
{
this.lawyerTableAdapter.FillBy(this.seniorProjectDb1DataSet.Lawyer);
}
catch (System.Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}
}
private void fillByToolStripButton1_Click(object sender, EventArgs e)
{
try
{
this.lawOfficeTableAdapter.FillBy(this.seniorProjectDb1DataSet.LawOffice);
}
catch (System.Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}
}
private void lawyersQueryToolStripButton_Click(object sender, EventArgs e)
{
try
{
this.lawyerTableAdapter.lawyersQuery(this.seniorProjectDb1DataSet.Lawyer);
}
catch (System.Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}
}
private void lawyerBindingSource_CurrentChanged(object sender, EventArgs e)
{
}
}
}
When the application is running, then the newly insterted/updated data is displayed correctly?
It's when you shutdown the application the changes are lost?
If so, that's probably because the database is overwritten again.
Check this thread for more info:
Why does "Copy if newer" not copy a file when the file is updated?
You need to use Update TableAdapter Method to save data in Db other than in your grid:
this.lawOfficeTableAdapter.Update(this.seniorProjectDb1DataSet.LawOffice);
this.lawyerTableAdapter.Update(this.seniorProjectDb1DataSet.Lawyer);
I'm creating a custom internet browser in c# using the webbrowser control.
And it works i can load sites and browse around and all that.
But with some sites (with alot of pictures and such) he wont put everything in the right spot so i will get text blocks inside images and vice versa.
How do i solve this ?
My code :
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 WindowsFormsApplication13
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
WB1.Navigate("http://nos.nl");
}
private void GoBtn_Click(object sender, EventArgs e)
{
if (AddRsBsr.Text.StartsWith("http://"))
{
WB1.Navigate(AddRsBsr.Text);
}
else if (AddRsBsr.Text.StartsWith("https://"))
{
WB1.Navigate(AddRsBsr.Text);
}
else
{
WB1.Navigate("http://www.googl.com/search?q=" + AddRsBsr.Text);
}
}
private void AddRsBsr_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Return)
{
if (AddRsBsr.Text.StartsWith("http://"))
{
WB1.Navigate(AddRsBsr.Text);
}
else if (AddRsBsr.Text.StartsWith("https://"))
{
WB1.Navigate(AddRsBsr.Text);
}
else
{
WB1.Navigate("http://www.googl.com/search?q=" + AddRsBsr.Text);
}
}
}
private void BackBtn_Click(object sender, EventArgs e)
{
WB1.GoBack();
}
private void StopBtn_Click(object sender, EventArgs e)
{
WB1.Stop();
}
private void HomeBtn_Click(object sender, EventArgs e)
{
WB1.Navigate("http://google.nl");
}
}
}
Now i know my code isn't clean and all but im doing that right now while waiting and hoping for an answer.
Thanks !
The WebBrowser component defaults to rendering in ... IE7 mode.
To have it behave as IE10/11 you need to make the registry changed described here (FEATURE_BROWSER_EMULATION): http://msdn.microsoft.com/en-us/library/ie/ee330730(v=vs.85).aspx