using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;namespace searchrow
{
class Test
{
static void Main(string[] args)
{
SqlConnection con = new SqlConnection(@"server=.\hwq;database=northwind;uid=sa;pwd=sa");
con.Open();
SqlDataAdapter sda = new SqlDataAdapter("select CustomerID,CompanyName from Customers",con);
SqlCommandBuilder scb = new SqlCommandBuilder(sda); DataSet ds = new DataSet();
sda.Fill(ds,"客户表");
sda.Update(ds,"客户表");
Console.WriteLine("Before deal wo have count is:{0}.",ds.Tables["客户表"].Rows.Count); DataColumn[] keys=new DataColumn[1];
keys[0]=ds.Tables["客户表"].Columns["CustomerID"];
ds.Tables["客户表"].PrimaryKey = keys; DataRow datarow = ds.Tables["客户表"].Rows.Find("ShuangWei"); if (datarow == null)
{
Console.WriteLine("NO Find!Do you want to add?If want input Y,or N!");
string s=Console.ReadLine();
if (s.ToLower() == "y")
{
DataRow datarows = ds.Tables["客户表"].NewRow();
datarows["CustomerID"] = "ShuangWei";
datarows["CompanyName"] = "Doublewei Inc.";
ds.Tables["客户表"].Rows.Add(datarows);
sda.Update(ds, "客户表");
}
else
{
Console.WriteLine("Finished!");
}
}
else
{
Console.WriteLine("SuccessfullY Find!");
}
sda.Update(ds,"客户表");
con.Close();
Console.WriteLine("After deal ,wo have count:{0}.",ds.Tables["客户表"].Rows.Count);
Console.ReadKey(); }
}
}
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;namespace searchrow
{
class Test
{
static void Main(string[] args)
{
SqlConnection con = new SqlConnection(@"server=.\hwq;database=northwind;uid=sa;pwd=sa");
con.Open();
SqlDataAdapter sda = new SqlDataAdapter("select CustomerID,CompanyName from Customers",con);
SqlCommandBuilder scb = new SqlCommandBuilder(sda); DataSet ds = new DataSet();
sda.Fill(ds,"客户表");
sda.Update(ds,"客户表");
Console.WriteLine("Before deal wo have count is:{0}.",ds.Tables["客户表"].Rows.Count); DataColumn[] keys=new DataColumn[1];
keys[0]=ds.Tables["客户表"].Columns["CustomerID"];
ds.Tables["客户表"].PrimaryKey = keys; DataRow datarow = ds.Tables["客户表"].Rows.Find("ShuangWei"); if (datarow == null)
{
Console.WriteLine("NO Find!Do you want to add?If want input Y,or N!");
string s=Console.ReadLine();
if (s.ToLower() == "y")
{
DataRow datarows = ds.Tables["客户表"].NewRow();
datarows["CustomerID"] = "ShuangWei";
datarows["CompanyName"] = "Doublewei Inc.";
ds.Tables["客户表"].Rows.Add(datarows);
sda.Update(ds, "客户表");
}
else
{
Console.WriteLine("Finished!");
}
}
else
{
Console.WriteLine("SuccessfullY Find!");
}
sda.Update(ds,"客户表");
con.Close();
Console.WriteLine("After deal ,wo have count:{0}.",ds.Tables["客户表"].Rows.Count);
Console.ReadKey(); }
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货