insert data into database?
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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void btnInsert_Click(object sender, EventArgs e)
{
string a = "abc";
SqlConnection conn = new SqlConnection(@Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True;User Instance=True;);
try
{
conn.Open();
SqlCommand cmd = new SqlCommand("INSERT INTO temp(name) VALUES ('a')", conn);
cmd.ExecuteNonQuery();
MessageBox.Show("Connection Successful.");
}
catch (SqlException ex)
{
MessageBox.Show("There is an Error" + ex);
}
finally
{
conn.Close();
MessageBox.Show("Connection Closed");
}
}
}
}
this is my code of form it is not working.......... Please help me out
Comments
import java.sql.*;
/**
* JdbcInsert1.java - Demonstrates how to INSERT data into an SQL
* database using Java JDBC.
*/
class JdbcInsert1 {
public static void main (String[] args) {
try {
String url = "jdbc:msql://200.210.220.1:1114/Demo";
Connection conn = DriverManager.getConnection(url,"","");
Statement st = conn.createStatement();
st.executeUpdate("INSERT INTO Customers " +
"VALUES (1001, 'Simpson', 'Mr.', 'Springfield', 2001)");
st.executeUpdate("INSERT INTO Customers " +
"VALUES (1002, 'McBeal', 'Ms.', 'Boston', 2004)");
st.executeUpdate("INSERT INTO Customers " +
"VALUES (1003, 'Flinstone', 'Mr.', 'Bedrock', 2003)");
st.executeUpdate("INSERT INTO Customers " +
"VALUES (1004, 'Cramden', 'Mr.', 'New York', 2001)");
conn.close();
} catch (Exception e) {
System.err.println("Got an exception! ");
System.err.println(e.getMessage());
}
}
}
There are distinctive scripting languages which could accomplish this. i for my section use very own domicile page. there are a number of loose scripts accessible which you are able to use as examples to get you began. you will discover them by looking any of the quest engines.