you have read just inserting code on particular event using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; using System.IO; namespace HotelProject { public partial class NewEmployee : Form { SqlConnection con; SqlCommandBuilder cmdb; SqlDataAdapter da; DataSet ds; public NewEmployee() { con = new SqlConnection("Data source=JBB-F906306D8CC\\SQLEXPRESS;Initial Catalog=Hotel;Integrated Security=SSPI"); InitializeComponent(); } private void btnBrowseImagePath_Click(object sender, EventArgs e) { OpenFileDialog op = new OpenFileDialog(); if (op.ShowDialog() == DialogResult.OK) { txtBrowseImagePath.Text = op.FileName; } } private void btnSubmitRecord_Click(object sender, EventArgs e) { con.Open(); da = new SqlDataAdapter("Select * From EmployeeDetails", con); cmdb = new SqlCommandBuilder(da); ds = new DataSet("EmployeeDetails"); if (txtBrowseImagePath.Text != "") { FileStream fs = new FileStream(txtBrowseImagePath.Text, FileMode.OpenOrCreate, FileAccess.Read); byte[] rawdata = new byte[fs.Length]; fs.Read(rawdata, 0, System.Convert.ToInt32(fs.Length)); fs.Close(); da.Fill(ds, "EmployeeDetails"); DataRow dr = ds.Tables["EmployeeDetails"].NewRow(); dr["FullName"] = txtFullName.Text; dr["FatherName"] = txtFatherName.Text; dr["DateOfBirth"] = maskedTxtDateofBirth.Text; dr["Gender"] = cmbgender.SelectedItem.ToString(); dr["Address"] = txtAddress.Text; dr["City"] = txtCity.Text; dr["Country"] = cmbCountry.SelectedItem.ToString(); dr["PhoneNo"] = txtPhone.Text; dr["EMailID"] = txtEMailId.Text; dr["LicenceNo"] = txtLicence.Text; dr["EmployeeHotelId"] = txtEhotelid.Text; dr["DepartmentName"] = cmbDepartmentName.SelectedItem.ToString(); dr["Designation"] = cmbDesignation.SelectedItem.ToString(); dr["Qualification"] = cmbQualification.SelectedItem.ToStrin
seoamitk
Posts
-
Query execution problen in C# program -
Database connection questionhi ?xml version="1.0" encoding="utf-8" ? <configuration> <appSettings> <add key="Accesskey" value="Data source=.;Initial catalog=kirti;user id=sa;Password=./> </appSettings> </configuration> using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace WindowsApplication9 { public partial class Form1 : Form { SqlConnection connection; string con; public Form1() { con = System.Configuration.ConfigurationSettings.AppSettings["Accesskey"].ToString(); connection = new SqlConnection(con); InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { try { connection.Open(); SqlCommand commad = new SqlCommand("select *from " + textBox1.Text.ToString() + "", connection); SqlDataAdapter ad = new SqlDataAdapter(commad); DataSet ds = new DataSet(); ad.Fill(ds); dataGridView1.DataSource = ds.Tables[0]; } catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); } finally { connection.Close(); } } } } This code is writren in C# you have just convert into VB.NET.
-
Database connection questionHi You can an app.config file to your project and write this code into it if you have done this write this code your destination form where you have to make connection. using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace WindowsApplication9 { public partial class Form1 : Form { SqlConnection connection; string con; public Form1() { con = System.Configuration.ConfigurationSettings.AppSettings["Accesskey"].ToString(); connection = new SqlConnection(con); InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { connection.Open(); } } } Here this code writern in C# language you have to just convert it into VB.NET.
-
Back Up MsSql 2005 Using C# CodeSqlConnection connection = new SqlConnection("Connectionstring"); SqlCommand command = new SqlCommand("BACKUP DATABASE databasename TO DISK = 'path of destination'", connection); int effect = command.ExecuteNonQuery(); if (effect < 0) { MessageBox.Show("Back Up Created"); }