Need Help Here.......
I'm using visual C#:
How to insert the value that user have entered combobox and click button.The value will sent into database.This is in form1.
In form2,if click button it will display in listbox.There also got another button to to delete the value according the index have chose using cursour.
I'm using sql server 2005,the were connection problem.How to know the server name for my computer. Below is the coding I have done but cant work......
Database name is testing.mdf,table name display,field is value.
////////////////////
form1
/////////////////// - using System;
-
using System.Collections.Generic;
-
using System.ComponentModel;
-
using System.Data.SqlClient;
-
using System.Data;
-
using System.Drawing;
-
using System.Text;
-
using System.Windows.Forms;
-
-
namespace test1
-
{
-
public partial class Form1 : Form
-
{
-
DataTable datatable;
-
-
-
public Form1()
-
{
-
InitializeComponent();
-
}
-
-
private void button1_Click(object sender, EventArgs e)
-
{
-
string connectionString = "server=P-III;database=testing;uid=sa;pwd=;";
-
SqlConnection conn = new SqlConnection(connectionString);
-
-
?????? for inserting I don't know much.
-
}
-
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
-
{
-
-
}
-
}
-
}
///////////////////////////////////
form2
////////////////////////////////// - using System;
-
using System.Collections.Generic;
-
using System.ComponentModel;
-
using System.Data.SqlClient;
-
using System.Data;
-
using System.Drawing;
-
using System.Text;
-
using System.Windows.Forms;
-
-
namespace test
-
{
-
public partial class Form1 : Form
-
{
-
DataTable datatable;
-
int currRec = 0;
-
int totalRec = 0;
-
-
public Form1()
-
{
-
InitializeComponent();
-
}
-
-
private void button1_Click(object sender, EventArgs e)
-
{
-
string connectionString = "server=P-III;database=testing;uid=sa;pwd=;";
-
SqlConnection conn = new SqlConnection(connectionString);
-
-
string commandString = "SELECT value from display";
-
-
SqlDataAdapter dataAdapter = new SqlDataAdapter(commandString, conn);
-
DataSet ds = new DataSet();
-
dataAdapter.Fill(ds, "prog");
-
-
datatable = ds.Tables["prog"];
-
currRec = 0;
-
totalRec = datatable.Rows.Count;
-
-
FillControls();
-
}
-
-
private void FillControls()
-
{
-
listBox1.Text = datatable.Rows[currRec]["display"].ToString();
-
-
}
-
-
private void button2_Click(object sender, EventArgs e)
-
{
-
????? to delete the value in the list one by one .
-
}
-
-
-
}
-
}
Tq in advance. If get the solution of sample coding is appreaciated.
2 1507
There is lots of way to accomplish this...
U can use the following code... - Dim conn As SqlConnection = New SqlConnection(_connectionString) 'Connection Parameters
-
Dim cmd As SqlCommand = New SqlCommand("INSERT INTO Customer " & _
-
" (CustomerId, CustomerName, ContactName,CustomerRank, Occupation,Address1,Address2,City,Telephone,Mobile,Fax,Email,UserCode) " & _
-
" Values(@id, @name, @contact, @Rank, @occupation,@add1,@add2,@city,@tel,@mob,@fax,@mail,@uid)", conn)
-
-
cmd.Parameters.Add("@id", SqlDbType.VarChar, 50).Value = Your control Reference
-
cmd.Parameters.Add("@name", SqlDbType.VarChar, 200).Value = Your control Reference
-
'Setting Parameters
-
// Put value in that way for all parameters
-
Try
-
conn.Open()
-
-
cmd.ExecuteNonQuery()
-
-
-
Catch e As Data.SqlClient.SqlException
-
' Handle exception.
-
Throw New ArgumentException(e.Message)
-
Finally
-
conn.Close()
-
End Try
-
-
Return 1
Tq very much.It's help me
Sign in to post your reply or Sign up for a free account.
Similar topics
by: EricRobineau |
last post by:
hello
I have a DB with many inter-related tables (MySQL)
My main table called "content" has almost only foreign keys (integers)
some have a 3 level relation (ex: content->city->region->country)
...
|
by: Sans Spam |
last post by:
Greetings! I have a table that contains all of the function
permissions within a given application. These functions are different
sections of a site and each has its own permissions (READ, WRITE,...
|
by: Fred |
last post by:
Hi.
How does one display a confirmation message of either 'Record Updated' or
'Recorded Added"?
I've tried the form afterupdate and afterinsert but the afterupdate occurs
on an insert too?
So...
|
by: Eustice Scrubb |
last post by:
In line coding problem. Here's my code:
<script language="VB" runat="server">
Dim myConnection As SqlConnection
Sub Page_Load(Src As Object, e As EventArgs)
' Create a connection to the SQL...
|
by: Brad Baker |
last post by:
I'm trying to write a simple asp.net page which updates some data in a SQL
database. At the top of the page I have the following code:
<%@ Page Language="C#" Debug="true" %>
<%@ import...
|
by: martin.wong |
last post by:
Hi,
sorry if this is too rudimentary.
I've got an ASP page with CODEPAGE=932 setup as a form. Encoding is
SHIFT_JIS
In it, the user will put in some details in Japanese and submit
Another...
|
by: assgar |
last post by:
Hi
Developemnt on win2003 server. Final server will be linux
Apache,Mysql and PHP is being used.
I use 2 scripts(form and process).
The form displays multiple dynamic rows with chechboxs,...
|
by: kisalabs |
last post by:
I have been trying to insert a new record into an access database and cannot get any of the scripts to work.. I can access the db and pull up/display records but cannot get one added. Please help. ...
|
by: =?Utf-8?B?bXBhaW5l?= |
last post by:
Hello,
I am completely lost as to why I can't update a DropDownList inside a
DetailsView after I perform an insert into an object datasource. I tried to
simply it down to the core demostration:...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |