小萌新一个,求大神指点
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
using System.Security.Policy;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
string lianjie = "server=.;database=T7;uid=sa;pwd=123456";
SqlConnection a = new SqlConnection(lianjie);
a.Open();
if (a.State == ConnectionState.Open)
{
Console.WriteLine("序号\t游戏名称\t游戏类型\t\t游戏价格\t库存数量\t小计");
string sql = "insert into games2(name,leixing,price,kucun,xiaoji) select'纪念碑谷','冒险解谜类手机游戏'" +
",30,100,3000 union select'刺客信条','角色扮演类手机游戏',28,100,2800 union select'鳄鱼爱洗澡','休闲益智类手机游戏',6,100,600";
SqlCommand b = new SqlCommand(sql, a);
string sql2 = string.Format("select ID,name,leixing,price,kucun,xiaoji from games2");
SqlCommand cmd = new SqlCommand(sql2, a);
SqlDataReader r = b.ExecuteReader();
while (r.Read())
{
string id = r["ID"].ToString();
string name = r["name"].ToString();
string price = r["price"].ToString();
string kucun = r["kucun"].ToString();
string xiaoji = r["xiaoji"].ToString();
string leixing = r["leixing"].ToString();
Console.WriteLine("{0}\t《{1}》\t{2}\t{3}\t\t{4}\t\t{5}元", id, name, leixing, price, kucun, xiaoji);
}
r.Close();
string sum = "select sum(price*kucun)from games2";
SqlCommand c = new SqlCommand(sum, a);
string sum1 = string.Format("{0}", c.ExecuteScalar());
Console.WriteLine("库存游戏总金额:{0}元", sum1);
}
a.Close();
}
}
}